首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

自动分配id用getElementById找不到?解决思路

2012-02-11 
自动分配id用getElementById找不到?scriptlanguage javascript with(document){write( table)w

自动分配id用getElementById找不到?
<script   language   = "javascript ">
with(document)
{
write( " <table> ");
write( " <tr> ");

for(var   a   =   0;   a <2;a   ++)
{
write( " <td   id   =\ "calcell\ "   > ");
write( " <font   id   =\ "celltext\ "   Victor   =\ "eric\ "> ");
write(a);
write( " </font> ");
write( " </td> ");
}

write( " </tr> ");
write( " </table> ");

write( " <input   type   =\ "button\ "   value   =\ "button\ "   id   =\ "button1\ "onclick   =\ "aa();\ "> ");
}


function   aa()
{
var   s   =100;
for(var   i   =0;i   <   2;i++)
{

celltext[i].Victor   =   s++;
<!--   alert(celltext[i].Victor);     -->



alert(document.getElementById(celltext[i]).Victor);    

}

}

</script>


[解决办法]
alert(document.getElementById( "celltext ").Victor);

[解决办法]
你最好 write( " <font id = 'celltext " + a + " ' Victor =\ "eric\ "> ");

alert(document.getElementById( "celltext " +a ).Victor);
[解决办法]
不可能,肯定可以啊
[解决办法]
你的alert(celltext[i].Victor); 输出的是 100多,你怎么可能有这个ID的对象啊
[解决办法]
ID重名了呀。
[解决办法]
问题是用document.write写的,重id的元素连uniqueID都是一样的。

热点排行