【发布时间】:2013-08-14 22:09:15
【问题描述】:
var html = {
easyBB :
['easybbtutorials','www.easybbtutorials.com','http://i76.servimg.com/u/f76/17/83/35/07/easybb10.png'],
AvacWeb:
['AvacWeb','www.avacweb.com','http://i45.servimg.com/u/f45/16/35/08/55/new_lo12.png'],
easyBB2:
['easybbtutorials','www.easybbtutorials.com','http://i76.servimg.com/u/f76/17/83/35/07/easybb10.png'],
AvacWeb2 :
['AvacWeb','www.avacweb.com','http://i45.servimg.com/u/f45/16/35/08/55/new_lo12.png'],
easyBB3 :
['easybbtutorials','www.easybbtutorials.com','http://i76.servimg.com/u/f76/17/83/35/07/easybb10.png'],
AvacWeb3 :
['AvacWeb','www.avacweb.com','http://i45.servimg.com/u/f45/16/35/08/55/new_lo12.png']
};
var cont = document.getElementById('container');
for(var key in html){
for(var i =0;i<key.length;i++ ){
var name= '<span class="name">'+html[key][0] +'</span>',
link = '<span class="url"><a href="'+html[key][1]+'">'+html[key][1] +'</a></span>',
image = '<img src="'+html[key][2]+'" title="'+html[key][0]+'" />';
cont.innerHTML= '<div class="wrapper">'+ name + '<br />'+image+'<br />'+link+'</div>';
i++;
}
}
我正在尝试遍历我创建的 HTML 对象的每个键中的数组问题不知道该怎么做我现在已经尝试了多种方法,我相信(因为我发布)我做错了.我也试过这样做:html[key[i]][0] 虽然我当然得到了一个错误 i 没有定义。任何建议我做错了什么,截至目前它只是将一个数组发布到 html。
【问题讨论】:
-
html['easyBB'][0]或html.easyBB[0] -
看起来你只需要摆脱你的内部 for 循环......
标签: javascript arrays loops object