Jquery选择表行与复选框 [英] Jquery Selecting Table Rows with Checkbox

查看:101
本文介绍了Jquery选择表行与复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格为

<table id="rowclick2">
  <tbody>
    <tr >
      <td class="cb"><input type="checkbox" value="yes"></td>
      <td>row 1</td>
       <td>A</td>
    </tr>    
    <tr >
      <td class="cb"><input type="checkbox" value="yes" ></td>
      <td>row 2</td>
       <td>B</td>
    </tr>    
    <tr>
      <td class="cb"><input type="checkbox" value="yes"></td>
      <td>row 3</td>
      <td>C</td>  
    </tr>    
  </tbody>
</table>

其中,我想获取每个单元格(点击按钮时)的复选框

where I want to get each cell (when the button is clicked) in a row whose checkboxes are checked

我尝试过滤

  $('#test').click(function(){

      $('#rowclick2 tr').filter(':has(:checkbox:checked)').each(
          //get row values
      );
    });

这很简单,但我看不到我丢失了什么...

it's pretty simple yet I can't see what I am missing...

提前感谢

此处< a>是jsfiddle链接...

here is the jsfiddle link...

推荐答案

你几乎在那里:)

如果您希望在选中复选框的行中所有< td> s:

If you want all <td> s in rows where the checkbox is checked:

$('#rowclick2 tr').filter(':has(:checkbox:checked)').find('td');

例如

$('#rowclick2 tr').filter(':has(:checkbox:checked)').find('td').each(function() {
    // this = td element
});

更精细的 example 在JsFiddle上。

More elaborate example is on JsFiddle.

BTW

.filter (':has(:checkbox:checked)')可以写为 .has(':checkbox:checked')我,发现更容易阅读。

BTW
The .filter(':has(:checkbox:checked)') can be written as .has(':checkbox:checked') if you, like me, find that easier to read.

这篇关于Jquery选择表行与复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆