仅使用jQuery在特定行中获取值

我有一个表(id =“docsTable”),其行看起来类似于:

  Document Title Document Description.  

我需要遍历表,确定用户检查了哪些复选框,对于带有复选框的行,请获取第一个的值和下两个的文本。

我不需要构建集合:在每次迭代中,我想在其他地方更改一些元素。 对我来说,这不是困难的部分。 它试图弄清楚如何遍历表并仅选中带有选中复选框的s。

       
Document Title 1 Document Description.
Document Title 2 Document Description.
Document Title 3 Document Description.

您可以尝试沿着这条线:

 $('tr > td:first-child > input:checked').each(function() { // $(this).val() is the value of the input // $(this).parent().siblings() will refer to the two 's // You can also try other traversal methods like $(this).parent().next() }); 

希望这有效并且有所帮助!

 $('#docsTable > tr > td > input:checked').each(function(i,element){ var el = $(element); alert( el.val() ); alert( el.parent().siblings(':eq(0)').html() ); alert( el.parent().siblings(':eq(1)').html() ); });