选择/取消选择jQuery中的所有复选框 [英] Select/deselect all checkboxes in jQuery

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

问题描述

我正在使用以下示例HTML代码。使用jQuery,我不确定如何使用 id =select-all来实现选择/取消全选来检查/取消选中以下所有<$ c的复选框$ c> name =p_v01

I am using the following sample HTML code below. With jQuery, I am unsure how to implement a "Select/Deselect All" using the id="select-all" to check / uncheck all the below checkboxes where name="p_v01"

<span style="font-size:8px;">Select All</span><br>&nbsp;
<input type="checkbox" name="select-all" id="select-all">
<span style="font-weight:bold;font-size:16px;padding-left:20px;">Emps</span>
<table summary="" role="presentation" class="checkbox_group">
  <tbody>
   <tr>
    <td>
     <input type="checkbox" id="P2_EMP_CB_0" name="p_v01" value="ANALYST">
     <label for="P2_EMP_CB_0">ANALYST</label>
    </td>
    <td>
     <input type="checkbox" id="P2_EMP_CB_1" name="p_v01" value="CLERK">
     <label for="P2_EMP_CB_1">CLERK</label>
    </td>
    <td>
     <input type="checkbox" id="P2_EMP_CB_2" name="p_v01" value="MANAGER">
     <label for="P2_EMP_CB_2">MANAGER</label>
    </td>
    <td>
     <input type="checkbox" id="P2_EMP_CB_3" name="p_v01" value="PRESIDENT">
     <label for="P2_EMP_CB_3">PRESIDENT</label>
   </td>
   <td>
    <input type="checkbox" id="P2_EMP_CB_4" name="p_v01" value="SALESMAN">
    <label for="P2_EMP_CB_4">SALESMAN</label>
  </td>
 </tr>
</tbody>

推荐答案

您可以使用:

$('#select-all').click(function() {
    $('input[name="p_v01"]').prop('checked',this.checked);    
});

小提琴演示

Fiddle Demo

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

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