为什么“儿童ID”没有返回任何值?循环应该工作,因为它计算正确的表行数...
<table>
<tbody>
<tr>
<td>
<input id="K9BEM" value"test12345" />
</td>
</tr>
<tr>
<td>
<input id="K9BEM" value"test6789" />
</td>
</tr>
</tbody>
</table>
var count = 1;
var postdata = {};
var listname = "WBEMLIST";
$('#bem_area tbody tr').each(function (index, element) {
countName = '0000' + count;
countName = countName.substring(countName.length - 4, countName.length);
postdata += "test=" + $(element).children("#K9BEM").val();
count++;
});
答案 0 :(得分:0)
首先,元素id
必须是唯一的。我已将它们改为使用类。
其次,children()
适用于直系后代。您的input
比tr
低两级。
第三,我不认为将字符串连接到对象就是你想要做的事情。
var count = 1;
var postdata = '';
var listname = "WBEMLIST";
$('#bem_area tbody tr').each(function (index, element) {
countName = '0000' + count;
countName = countName.substring(countName.length - 4, countName.length);
postdata += "test=" + $(element).find(".K9BEM").val();
count++;
});