Javascript 如何打印身份证

Javascript 如何打印身份证,javascript,Javascript,这是代码。此代码从facebook获取好友列表。它以name和id对的形式为每个朋友提供。我使用response[“data”]获取此信息,并将其存储在friends中。 当我打印朋友时,我会得到下面添加的内容: 第一名: if(loggedIn) { FB.api("/me/friends",function(response){ friends = response["data"]; totalToBeLoaded = friends.length;

这是代码。此代码从facebook获取好友列表。它以
name
id
对的形式为每个朋友提供。我使用
response[“data”]
获取此信息,并将其存储在
friends
中。 当我打印<代码>朋友时,我会得到下面添加的内容:

第一名:

if(loggedIn) {
    FB.api("/me/friends",function(response){
        friends = response["data"];
        totalToBeLoaded = friends.length;
      document.getElementById("status").innerHTML=friends;

  });
输出为:

[对象],[对象] 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象],[对象对象],[对象 对象]

秒: 如果我以这种方式更改上述代码:

if(loggedIn) {
  FB.api("/me/friends",function(response){
      friends = response["data"];
      totalToBeLoaded = friends.length;
    document.getElementById("status").innerHTML=friends[0].id;
  });
它会打印。0位置的id正确为

输出:

1243533622(id)

第三名: 因为如果我将其放入
while循环中并打印所有内容,会有更多ID:

if(loggedIn) {
  FB.api("/me/friends",function(response){
    friends = response["data"];
    totalToBeLoaded = friends.length;
    while(i<totalToBeLoaded)
      document.getElementById("status").innerHTML=friends[i].id;
  });
if(loggedIn){
FB.api(“/me/friends”),函数(响应){
朋友=响应[“数据”];
totalToBeLoaded=friends.length;

而(i问题的一部分是你的循环

totalToBeLoaded = friends.length;
while(i<totalToBeLoaded)
  document.getElementById("status").innerHTML=friends[i].id;

请注意
+=friends[i].id
。这将将当前id附加到status元素中,而不是每次都覆盖当前值。这可能会使查看发生了什么更容易。

问题的一部分是您的循环

totalToBeLoaded = friends.length;
while(i<totalToBeLoaded)
  document.getElementById("status").innerHTML=friends[i].id;

请注意
+=friends[i].id
。这将将当前id附加到status元素中,而不是每次都覆盖当前值。这可能会使查看发生了什么更容易。

您需要创建某种HTML来显示它们(目前每次都在替换HTML),然后在列表中迭代(当前不增加循环计数器)

var i,htmlist=“
    ”; 对于(i=0;i”+朋友[i].id+“”; } htmlList+=“
”; document.getElementById(“status”).innerHTML=htmlList;
您需要创建某种HTML来显示它们(当前每次都替换HTML),然后遍历列表(当前不增加循环计数器)

var i,htmlist=“
    ”; 对于(i=0;i”+朋友[i].id+“”; } htmlList+=“
”; document.getElementById(“status”).innerHTML=htmlList;
var i, htmlList = "<ul>";
for (i = 0; i < totalToBeLoaded; i++) {
  htmlList += "<li>" + friends[i].id + "</li>";
}
htmlList += "</ul>";
document.getElementById("status").innerHTML = htmlList;