jquery遍历表行和单元格,检查checkob,连接

我有一个包含多行的表。 表格中有几列带复选框。 我需要遍历每个复选框,在其中检查连接/连接来自该特定单元格的输入到同一行的其他输入。

你可以在这里看到一个小提琴: http : //jsfiddle.net/QS56z/10/

除了循环遍历行之外,我怎么能循环遍历每个

一旦我有了这个

如何在该td中查找名称以x开头的输入。 一旦找到连接/加入从该输入到行中的输入。

我希望这是有道理的。

本质上:我想加入(系列)到(大小)到(等级),其中系列和等级在同一行,并且每行有几种尺寸。 每个结果必须写入当前正在处理的TD。

我已经达到了这一点但却陷入困境:

 function createcodes(){ alert('running'); //run through each row $('.authors-list tr').each(function(){ //processing this row //how to process each cell(table td) where there is checkbox $($(this).find('input[name^="line"]').val( $('$(this).find('input[name^="family"]'').val() + ' ' + // common input(family) on row, use for all table cells(td) $('#$(this).find('input[name^="size"]'').val() + ', ' + // this cells input called size, unique to this cell only $('#$(this).find('input[name^="grade"]'').val() // common input(grade) on row, use for all table cells(td) ); // end of cell row processing }); //end of rows processing } 

一如既往地谢谢。

http://jsfiddle.net/QS56z/10/

我的HTML是:

 

请记住,有多行。 谢谢。

更新

我已经更新了你的演示: http : //jsfiddle.net/terryyounghk/QS56z/18/

另外,我已将两个^=更改为*= 。 见http://api.jquery.com/category/selectors/

并注意:checked选择器。 见http://api.jquery.com/checked-selector/

 function createcodes() { //run through each row $('.authors-list tr').each(function (i, row) { // reference all the stuff you need first var $row = $(row), $family = $row.find('input[name*="family"]'), $grade = $row.find('input[name*="grade"]'), $checkedBoxes = $row.find('input:checked'); $checkedBoxes.each(function (i, checkbox) { // assuming you layout the elements this way, // we'll take advantage of .next() var $checkbox = $(checkbox), $line = $checkbox.next(), $size = $line.next(); $line.val( $family.val() + ' ' + $size.val() + ', ' + $grade.val() ); }); }); } 

试试这个:

 function createcodes() { $('.authors-list tr').each(function () { //processing this row //how to process each cell(table td) where there is checkbox $(this).find('td input:checked').each(function () { // it is checked, your code here... }); }); }