选择/取消选择所有复选框 [英] Select/Deselect All Checkboxes

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

问题描述

使用下面的示例HTML代码,使用jQuery我不确定如何使用 id =select-all执行选择/取消选择所有/取消选中以下所有复选框 name =p_v01



感谢。

 < span style =font-size:8px; >全选< / span>< br>& nbsp; 
< input type =checkboxname =select-allid =select-all>
< span style =font-weight:bold; font-size:16px; padding-left:20px;> Emps< / span>
< table summary =role =presentationclass =checkbox_group>
< tbody>
< tr>
< td>
< input type =checkboxid =P2_EMP_CB_0name =p_v01value =ANALYST>
< label for =P2_EMP_CB_0> ANALYST< / label>
< / td>
< td>
< input type =checkboxid =P2_EMP_CB_1name =p_v01value =CLERK>
< label for =P2_EMP_CB_1> CLERK< / label>
< / td>
< td>
< input type =checkboxid =P2_EMP_CB_2name =p_v01value =MANAGER>
< label for =P2_EMP_CB_2> MANAGER< / label>
< / td>
< td>
< input type =checkboxid =P2_EMP_CB_3name =p_v01value =PRESIDENT>
< label for =P2_EMP_CB_3> PRESIDENT< / label>
< / td>
< td>
< input type =checkboxid =P2_EMP_CB_4name =p_v01value =SALESMAN>
< label for =P2_EMP_CB_4> SALESMAN< / label>
< / td>
< / tr>
< / tbody>

解决方案>

您可以使用:

  $('#select-all' $ b $('input [name =p_v01]')。prop('checked',this.checked); 
});

Fiddle Demo


Using the following sample HTML code below, using 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"

Any guidance would be great.

Thanks.

<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>

解决方案

You can use:

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

Fiddle Demo

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

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