如何打印身份证号码
以下是密码。此代码从facebook获取朋友列表。它来为每个朋友name
和id
对。我得到这个使用response["data"]
并将其存储在friends
。 当我打印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;
});
它打印。ID在0位置正确的
输出:
1243533622(ID)
三: 由于有多个ID,如果我把它放在一个while-loop
和打印一切:
if(loggedIn) {
FB.api("/me/friends",function(response){
friends = response["data"];
totalToBeLoaded = friends.length;
while(i<totalToBeLoaded)
document.getElementById("status").innerHTML=friends[i].id;
});
输出:
没有被打印。
如何打印所有id
的?问题的
部分是你的循环
totalToBeLoaded = friends.length;
while(i<totalToBeLoaded)
document.getElementById("status").innerHTML=friends[i].id;
的i
值不会改变。你可能想重写这样的循环:
for(var i=0, j=friends.length; i < j; i++) {
document.getElementById("status").innerHTML += friends[i].id + '<br />';
}
请注意+= friends[i].id
。这是追加当前id到状态元素,而不是每次覆盖当前值。这可能会更容易看到发生了什么事情。
您需要创建某种HTML来显示它们全部(当前您每次都要更换html),然后遍历列表(当前您没有递增循环计数器)。
var i, htmlList = "<ul>";
for (i = 0; i < totalToBeLoaded; i++) {
htmlList += "<li>" + friends[i].id + "</li>";
}
htmlList += "</ul>";
document.getElementById("status").innerHTML = htmlList;
thanks.done一个很大的错误。感谢您指出..... – learnfromothers 2011-06-13 16:02:43