[英]Can I put jquery code in a bunch of pure javascript code?
Is it possible to insert my jquery code into a bunch of javascript code 是否可以将我的jquery代码插入一堆javascript代码中
I want to put the $ajax
jquery code into function getInfo()
but seem not work.I try to wrap all js code with document.ready
but not work too. 我想将$ajax
jQuery代码放入function getInfo()
但似乎无法正常工作。我尝试用document.ready
包装所有js代码,但也无法正常工作。
window.fbAsyncInit = function() {
FB.init({
appId: '201637766943985',
cookie: true,
xfbml: true,
version: 'v2.8'
});
FB.AppEvents.logPageView();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected.';
document.getElementById('fb_login').style.visibility = 'hidden';
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.';
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook';
}
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fb_login() {
FB.login(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected.';
document.getElementById('fb_login').style.visibility = 'hidden';
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'We are not logged in.';
} else {
document.getElementById('status').innerHTML = 'You are not logged into Facebook';
}
}, {
scope: 'email'
});
}
function getInfo() {
FB.api('/me', 'GET', {
fields: 'first_name,last_name,name,id,email'
}, function(response) {
////////call jquery AJAX here/////////////////////
});
}
function fb_logout() {
FB.logout(function() {
document.location.reload();
});
}
Since status is an ID
you need to write your jquery as 由于status is an ID
您需要将jquery编写为
$("#status").html("Hello <b>world!</b>");
Selectors in jquery begin with #
for ids and .
jQuery中的选择器以#
开头的ID和ID .
for classes. 上课。
Please refer this simple link to get an idea on how to use selectors 请参考这个简单的链接以了解如何使用选择器
http://www.w3schools.com/jquery/jquery_ref_selectors.asp http://www.w3schools.com/jquery/jquery_ref_selectors.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.