获取表中的子元素的值

时间:2014-02-03 20:55:52

标签: jquery input html-table each

为什么“儿童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++;
});

1 个答案:

答案 0 :(得分:0)

首先,元素id必须是唯一的。我已将它们改为使用类。

其次,children()适用于直系后代。您的inputtr低两级。

第三,我不认为将字符串连接到对象就是你想要做的事情。

http://jsfiddle.net/NcVTa/

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++;
});