假如一个页面有很多个id位summary的input
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />怎么才能在js中获得summary的数组呢?那么应该怎样用
document.getElementById( 'summary ')(我试过了,返回的不是一个数组)
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />
<input name='summary' id='summary' type='text' />怎么才能在js中获得summary的数组呢?那么应该怎样用
document.getElementById( 'summary ')(我试过了,返回的不是一个数组)
正解,就算你id都相同,但是用getElementById("summary");得到的只能是第一个id为summary<input>
的内容
或者用document.all.summary也是可以的
这个是微软专用的。建议不要使用这个方法。W3C标准是 document.getElementsByName('summary');<input name='summary' id='summary1' type='text' />
<input name='summary' id='summary2' type='text' />
<input name='summary' id='summary3' type='text' />
<input name='summary' id='summary4' type='text' />
或者document.getElementsByTag("input");
谢谢大家了,getElementByName这个貌似不能用报错getElementsByName()这个能用,谢谢大家了分数不多