我可以将jquery代码放在一堆纯JavaScript代码中吗?

时间:2016-11-03 04:18:43

标签: javascript jquery ajax

是否可以将我的jquery代码插入一堆javascript代码

我想将$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();
  });
}

1 个答案:

答案 0 :(得分:1)

status is an ID开始,你需要将你的jquery写成

$("#status").html("Hello <b>world!</b>");

jquery中的选择器以#表示ids,.表示。

请参阅此简单链接,了解如何使用选择器

http://www.w3schools.com/jquery/jquery_ref_selectors.asp