jquery 实现 checkbox的全选操作

<title>jQuery实现CheckBox全选、全不选</title>
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>    <script type="text/javascript">
        $(function() {
           $("#checkAll").click(function() {
                $(‘input[name="subBox"]‘).attr("checked",this.checked);
            });
            var $subBox = $("input[name=‘subBox‘]");
            $subBox.click(function(){
                $("#checkAll").attr("checked",$subBox.length == $("input[name=‘subBox‘]:checked").length ? true : false);
            });
        });
    </script>

</head>
<body>
    <div>
        <input id="checkAll" type="checkbox" />全选
        <input name="subBox" type="checkbox" />项1
        <input name="subBox" type="checkbox" />项2
        <input name="subBox" type="checkbox" />项3
        <input name="subBox" type="checkbox" />项4
    </div>
时间: 2024-07-28 22:50:23

jquery 实现 checkbox的全选操作的相关文章

checkbox 全选操作

1 <html> 2 <head></head> 3 <body> 4 <div id="places"> 5 <input type="checkbox" name="chx" value="1" onclick="_check_status(this)"/>香港 6 <input type="checkbox&quo

【Jquery】checkbox的全选和全不选

刚学Jquery,在做checkbox的全选全不选时遇到了一个问题,使用attr()方法的话, 只能成功全选和取消全选一次,第二次就不行了,如下面 $("#chkAll").click(function(){ if(this.checked==true){ $("#tab input[type='checkbox']").attr("checked",true); }else{ $("#tab input[type='checkbox'

jquery实现checkbox的全选

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>jQuery实现CheckBox全选.全不选</title> <meta charset="utf-8"> <script src="http://code.jquery.com/jquery-1.11.3.min.js"

jQuery实现checkbox的全选和反选

1 $(function () { 2 3 if ($(".chk_all")) { 4 5 $(".chk_all").click(function () { 6 $("input[checkname='choice']").prop("checked", $(this).prop("checked")); 7 }); 8 } 9 }); 如何使用: 1 <table > 2 <tr&g

jquery中checkbox的全选与反选

<script type="text/javascript"> 'use strict'; $(function () {  $("#c1").click(function () {     $('input[type="checkbox"]').prop("checked", this.checked)  }); }); </script> <body> <div id="

jQuery实现checkbox(复选框)选中、全选反选代码

谁都知道 在html 如果一个复选框被选中 是 checked="checked". 但是我们如果用jquery alert($("#id").attr("checked")) 会提示您是true而不是checked 所以很多朋友判断  if($("#id").attr("checked")=="true") 这个是错误的,其实应该是 if($("#id").attr

checkbox的全选、反选、多选等操作(js)

以下控件的name属性为DEPT_ID (案例中默认选中的checkbox,全选或者反选,对该控件无影响)//1.全选 function selectAllRight(){ $("input[name='DEPT_ID'").each(function() { $(this).prop("checked", true); }); } //2.反选 function reverseSelectRight(){     $("input[name='DEPT_

在项目中学习.NET的JQuery CheckBox方法(全选、取消全选、其他)

一.在项目中遇到的CheckBox的全选和取消全选以及其他等解决方案如下: // 对全选和取消全选的事件 $("#CheckAll").click(function () {                var checkedOfAll = $(this).prop("checked");                if (checkedOfAll == true) {                    $("input[id*='check']

JQUERY的给Check全选功能

//给Checkbox提供全选功能 $("#checkall").click(function(){ if(this.checked){ $("input[name='checkname[]']").each(function(){ this.checked = true; }); }else{ $("input[name='checkname[]']").each(function(){ this.checked = false; }); }