jquery1.11.1版本完成对checkbox的操作

1. 使用属性prop设置选中状态

2.使用:checked和:not(:checked)获取选中的元素

源码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>测试CheckBox</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<style>
div.content{
width:30%;
margin:auto;
border:1px dotted #0000ff;
background-color: #ffa0a0;
padding:10px;
}
div.sel span{
display: block;
}
.mt_s{
margin-top:5px;
}
</style>
</head>
<body>
<div class="content">
<h1>测试CheckBox</h1>
<div class="sel mt_s">
<span >按钮1<input type="checkbox" class="c1"></span>
<span>按钮2<input type="checkbox" class="c2"></span>
<span>按钮3<input type="checkbox" class="c3"></span>
<span>按钮4<input type="checkbox" class="c4"></span>
<span>按钮5<input type="checkbox" class="c5"></span>
</div>
<div class="op mt_s">
<button onclick="selectAll(true)">全选</button>
<button onclick="selectAll(false)">全消</button>
<button onclick="getCheck(true)">获取选择数据</button>
<button onclick="getCheck(false)">获取未选择数据</button>
</div>
<div class="sta mt_s">
<span class="blue"><strong>结果:</strong></span><span class="status"></span>
</div>
</div>
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
"use strict";
//全选/取消全选
function selectAll(bcheck){
var sel = getsel();
log(sel);
sel.prop("checked",bcheck);
}
//获取选中/未选中的记录
function getCheck(bcheck){
var sel = getsel();
var c;
if(bcheck){
c = sel.filter(":checked");
}
else{
c = sel.filter(":not(:checked)");
}
setStatus(c);
} //获取全部checkbox
function getsel(){
return $(".sel input:checkbox");
}
//更新查询结果
function setStatus(s){
var cName="";
log(s);
for(var i=0;i<s.length;i++){
cName +=$(s[i]).attr("class");
if(i<s.length-1){
cName +=","
}
}
cName = cName==""?"没有数据":cName;
$(".status").text(cName);
}
//记录控制台信息
function log(s){
console.log(s);
}
</script>
</body>
</html>

效果图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZ0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bXSq1OiW9dy1Z6ZQbkCq0v9lKDKW2MUhYa5KTGZu7XFpahvHt6micq6t8T6lpXAVb3a6XfnOjHJ/3NkX+mJl8Ao3wKNUOTyWo+J82HynVdzli2ocoXqJSIcKDSv2mRli50elDb+dDlZajZeIqiznI6XeN5HkfMp8avvTnc9759ae+uVtPYwK8d5QKcJJ9Kv/Y+rOfXQMPpdA2/dsR8drr2TxKapnnbv2lA1w5SXQ+KiV/L1rxdglzX987dEGRdIyjDKa61gyAV9fGw8Ws7V+0kkM/3CZThZmF3tZqGgV8DADgMvD8UADyCXwMAT+DXAMAj+DUA8AR+DQA8YujXutvNNBsBAFbC2K/N0LVGDLsXEACcEiu/VlIija7JnwEA9Fj6tVSVNC5sR79mciA8JsARMfFrfZMuKVd1R+HzGqSZNEkHAHbHxq/JhkWja9v7NXQNwDNW42utriuq3H1LlhwUXQM4GmuNr83NzVq6Ns9LatJpCr1vANgT2/E1JXL3c5LL0xwr+1neqEwnzB7SBnAEVhlfCy2MXqGUKjZV6WZo1qrpAMAWGI6vhaTqI+jRDPnTZ8MkGroGcBZWvD9Ur2uRxWuni5ecDc322bo2NR0A2AJDvxbqkUbXIv2KImTt2wzJi3YXNmYzOS8dANgL+/G17MY0QlaeZkih+jyLh6secV46ALAnRxhfU0bYhiPkAQBmc6znr+2ua7tnAABsWMmvAQDswrH8GgCADfg1APAEfg0APIJfAwBP4NcAwCP4NQDwBH4NADyCXwMAT+DXAMAj+DUA8MQEv8Zf/vKXv2f5q/BrBAKBcNqArhEIBG8BXSMQCN4CukYgELwFdI1AIHgL/wNB76W1lR/ECAAAAABJRU5ErkJggg==" alt="" />

jquery1.11 操作checkbox:全选、取消全选、获取选择元素、获取取消选择元素(总结)的更多相关文章

  1. checkbook全选/反选/全不选

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  2. jquery操作checkbox方法(全选、全不选、至少选择一个、选择值/文本)

    原文:http://blog.csdn.net/u014079773/article/details/52371382 在实际开发中我们经常操作checkbox,不仅仅要获得checkbox选中的值, ...

  3. 解决jquery操作checkbox全选全不选无法勾选问题

    最近在学习中使用jquery操作checkbox,使用下面方法进行全选.反选:$("input[name='checkbox']").attr("checked" ...

  4. Android开发CheckBox控件,全选,反选,取消全选

    在Android开发中我们经常会使用CheckBox控件,那么怎么实现CheckBox控件的全选,反选呢 首先布局我们的界面: <?xml version="1.0" enc ...

  5. JS对checkbox全选和取消全选

    需求:checkbox控制列表数据全选与取消全选择. 效果图: 1.html <body > <input type="button" name="in ...

  6. js实现checkbox组 全选和取消全选

    做后台管理程序时,用到一个checkbox组的全选和取消全选的功能, 主要是逻辑上的坑,理清后大概是: 1.全选点击后,小弟1~4都要选上,点击取消,小弟们也要取消 2.只要有一个小弟取消时,全选要取 ...

  7. jquery、js操作checkbox全选反选

    全选反选checkbox在实际应用中比较常见,本文有个不错的示例,大家可以参考下 操作checkbox,全选反选//全选 function checkAll() { $('input[name=&qu ...

  8. jquery checkbox全选,全不选,反选方法,jquery checkbox全选只能操作一次

    jquery checkbox全选,全不选,反选方法, jquery checkbox全选只能操作一次, jquery checkbox全选只有第一次成功 >>>>>&g ...

  9. Jquery CheckBox复选框 全选/取消全选 最佳实现方式 参考案例

    <input id="chkAll" type="checkbox" />全选/取消全选</div> <asp:Repeater ...

随机推荐

  1. Single Number(JAVA)

    Given an array of integers, every element appears twice except for one. Find that single one. Note: ...

  2. mysql的分页存储过程,能够传出总记录数

    最近用mysql + asp.net来写网站,既然mysql已经支持存储过程了,那么像分页这么常用的东西,当然要用存储过程啦 不过在网上找了一些,发现都有一个特点——就是不能传出总记录数,干脆自己研究 ...

  3. nodejs学习随机记录

    1. nodejs的顶层对象:global(nodejs中没有window) 2. nodejs一个文件就是一个模块 每个模块都有自己的作用域 通过var声明的变量,只属于当前模块下,并非全局的 va ...

  4. jQuery工具函数下

    测试操作 1.判断是否为数组对象 $(function () { //判断是否为数组对象 var arr = [1,2,3,4]; alert($.isArray(arr));//true }); 2 ...

  5. 在右键添加Cmder here选项,添加启动Cmder的快捷键

    右键菜单添加“Cmder here” 打开cmder,在其中输入: cmder /register user 或 cmder /register all 即可   设置启动cmder的快捷键 右键 C ...

  6. UVA 10943 How do you add?

    设函数 f(k)(n); 则: f(1)(n)=1; f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n); f(3)(n)=f(2)(0)+f(2)(1)+f(2) ...

  7. CodeForces 214B Hometask

    本题求n个数组成的大数,要求是2,3,5的倍数. 因为是2 和5 的倍数,所以个位为 0:所以若n个数中没有0,直接输出-1: 难点就是要求为3 的倍数. 因为若某个数为3的倍数,则其各位数的和必然是 ...

  8. VB.NET生成Excel,已存在提示框点否时报错

    如题 Exception from HRESULT: 0x800A03EC 最终没有好的解决方案,只好屏蔽掉 Try obook.SaveAs(excelSaveName) Catch ex As S ...

  9. 关于Thread的Runnable和Callable接口

    其实非常简单:其实他们的区别就是Callable有返回值并且可以抛出异常. /** * Represents a command that can be executed. Often used to ...

  10. 构造函时和this指针

    通常this指针在对象构造完毕后才完全生成,而在构造函数执行过程中,对象还没有完全生成,所以this指针也是没有完全生成的,在构造函数中使用this指针会存在问题,应该尽量避免. 构造函数中可以访问对 ...