我无法更改此脚本中的 href。但是 innerHTML 有效。怎么了?
<script>
FB.init({
appId: 1234,
cookie: true,
status: true,
xfbml: true
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
document.getElementById('test').href = 'http://www.example.com/auth/login';
// document.getElementById('index-facebook-login-button').innerHTML = '<a class="index-facebook-login-button" href="http://www.example.com/auth/login" target="_self"></a>';
} else if (response.status === 'not_authorized') {
document.getElementById('test').href += 'http://www.example.com/connectfacebook';
//this works!!!
//document.getElementById('index-facebook-login-button').innerHTML = '<a class="index-facebook-login-button" href="http://www.example.com/connectfacebook" target="_self"></a>';
} else {
document.getElementById('test').href += 'http://www.example.com/connectfacebook';
//this works!!!
// document.getElementById('index-facebook-login-button').innerHTML = '<a class="index-facebook-login-button" href="http://www.example.com/connectfacebook" target="_self"></a>';
}
});
</script>
<div id="index-facebook-login-text" onLoad="FB.getLoginStatus();">
some text here
<div id="index-facebook-login-button" style="margin-left: 25px;">
<a id="test" class="index-facebook-login-button" href="" target="_self"></a>
</div>
</div>