选择表行并使用JQuery选中复选框 [英] Select table row and check checkbox using JQuery

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

问题描述

我有一张桌子,我想选择满足我的条件的行并选中它们各自的复选框.假设我要获取日期为2013-03-21的行.如何使用JQuery做到这一点?

I have a table and I want to select the rows that satisfy my criteria and check their respective checkbox. Let's say I want to get the rows with date 2013-03-21. How can I do this using JQuery?

<table>
<tr>
    <td>
        Record1
    </td>
    <td>
        2013-03-21
    </td>
    <td>
        <input type="checkbox"/>
    </td>
</tr>
<tr>
    <td>
        Record2
    </td>
    <td>
        2013-03-22 
    </td>
    <td>
        <input type="checkbox"/>
    </td>
</tr>
<tr>
    <td>
        Record3
    </td>
    <td>
        2013-03-21
    </td>
    <td>
        <input type="checkbox"/>
    </td>
</tr>
</table>

推荐答案

$("table tr").each(function () {
    if ($(this).find("td:eq(1)").text().trim() == '2013-03-21') {
     $(this).find("input[type=checkbox]").attr("checked", true);
  }
});

演示

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

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