本文介绍了单击按钮,使用jquery检查标记所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表结构的样子,

This is how my table structure looks,

 <table>
    <tbody>
    <tr>
    <td id="**SelectCheckBox**" class="helpBod">
    <input id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl01_CheckBox0" type="checkbox"  name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl01$CheckBox0"/>
    </td>
    <td>
    </td>
    </tr>
    <tr>
    <td id="**SelectCheckBox**" class="helpBod">
    <input id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl02_CheckBox1" type="checkbox"  name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl02$CheckBox1"/>
    </td>
   <td>
    </td>
    </tr>
    <tr>
    </tbody>
</table>

我有一个SelectAll按钮,我将调用一个jQuery函数来选中所有复选框

I have a button SelectAll im going to call a jquery function to check mark all the checkbox

功能外观

function jqCheckAll() {
        $("td#" + 'SelectCheckBox' + 'input:checkbox').attr('checked', true);

      }

问题是,这将仅选中复选框,如果我有100个复选框,我想在单击全选"按钮时选中所有这100个复选框.

problem is this will check mark only only checkbox what if i have 100 checkbox, i want to check mark all the this 100 checkbox on click of select all button.

推荐答案

@sameer,您想要做的是将一个类添加到要检查的所有复选框中.在这里,我将一个类"checkall"添加到将被选中的复选框.

@sameer, what you want to do is add a class to all the checkboxes you want checked.Here I added a class "checkall" to the checkboxes that will be checked.

<input type="button" name="checkit" id="checkit" value="Check All">

 <table>
    <tbody>
    <tr>
    <td>
    <input type="checkbox" class="checkall" name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl01$CheckBox0" id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl01_CheckBox0" />
    </td>
    <td>
    <input type="checkbox" name="chk1" id="chk1" />
    </td>
    </tr>
    <tr>
    <td>
    <input type="checkbox" class="checkall" name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl02$CheckBox1" id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl02_CheckBox1" />
    </td>
    <td>
   <input type="checkbox" name="chk2" id="chk2" />
    </td>
    </tr>
    <tr>
    </tbody>
</table>

然后jQuery很简单.

The jQuery is then simple.

$('#checkit').click(function() {
    $('input:checkbox.checkall').attr('checked','checked');
    return false;
});

这篇关于单击按钮,使用jquery检查标记所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:59