js for 循环问题

[复制链接]
查看11 | 回复1 | 2008-6-27 16:51:33 | 显示全部楼层 |阅读模式
请问下,为什么这样就是正常的
for (a=0;a<6;a++) {
alert(a)
}
而这样a的值就全是 0
for (a=0;a<6;a++) {
alert(a)
n2="yx"+a
if(n==n2){
}
else{
n2.style.width="";
n2.style.height="";
n2.style.backgroundImage="";
}
}
问题已经找到,是这三句引起的
n2.style.width="";
n2.style.height="";
n2.style.backgroundImage="";
n2是变量,应该如何写呢

回复

使用道具 举报

千问 | 2008-6-27 16:51:33 | 显示全部楼层
n2是控件名是么?那就这么写:else{ document.getElementById(n2).style.width=""; document.getElementById(n2).style.height=""; document.getElementById(n2).style.backgroundImage=""; }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行