我有几个输入:如何通过jquery按索引名访问元素?
<input type="text" name="entry[1]" value="aaa" id="firstEntry" />
<input type="text" name="entry[2]" value="bbb" id="secondEntry" />
<input type="text" name="entry[3]" value="ccc" id="thirdEntry" />
如何获得 “2” 时,我知道,元素ID为 “secondEntry”?
var name = $("#secondEntry").attr('name'); // name = "entry[2]"
但是如何获得索引2? 我只需要知道索引(2),而不是全名(entry [2])。
如果你想它作为一个数字,'VAR IND = parseInt函数(I [1])'。但从正则表达式中删除“条目”,因此它不易碎(不会因名称更改而中断)。 – 2010-01-19 11:12:59