我同时使用 Facebook SDK 和 jQuery ...由于某种原因,加载 Facebook SDK 后,$
不再作为 jQuery 对象工作。我所有的 jQuery 调用仍然有效,但我必须使用jQuery
而不是$
... 请参阅下面的示例。我的页脚中还有其他代码,它们只是 jQuery 的东西,而且在$
那里也不起作用。一切功能完美,但我讨厌这个,并希望能够$
用作 jQuery 的快捷方式!我怎样才能$
回来?
<script type='text/javascript' src='http://x.com/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script>
window.fbAsyncInit = function () {
FB.init({ // (this code straight from FB developer docs)
appId: '1234123412341234',
channelUrl: '//mysite.com/channel.html',
status: true,
cookie: true,
xfbml: true
});
function checkLoginStatus(response) {
if(response && response.status == 'connected') {
jQuery('#login-btn').hide();
jQuery('#logout-btn').show();
console.log('User ID: ' + response.authResponse.userID);
} else {
jQuery('#login-btn').show();
jQuery('#logout-btn').hide();
}
}
// Load the SDK asynchronously (this code straight from FB developer docs)
(function (d) {
var js, id = 'facebook-jssdk',
ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>