jquery checkbox用法汇总
来源:http://www.jb51.net/article/75717.htm
1、全选
|
1
2
3
|
$("#btn1").click(function(){ $("input[name='checkbox']").attr("checked","true"); }) |
2、取消全选(全不选)
|
1
2
3
|
$("#btn2").click(function(){ $("input[name='checkbox']").removeAttr("checked"); }) |
3、选中所有奇数
|
1
2
3
|
$("#btn3").click(function(){ $("input[name='checkbox']:odd").attr("checked","true"); }) |
4、选中所有偶数
|
1
2
3
|
$("#btn6").click(function(){ $("input[name='checkbox']:even").attr("checked","true"); }) |
5、反选
|
1
2
3
4
5
6
7
8
9
10
11
12
|
$("#btn4").click(function(){ $("input[name='checkbox']").each(function(){ if($(this).attr("checked")) { $(this).removeAttr("checked"); } else{ $(this).attr("checked","true"); } }) }) |
或者
|
1
2
3
4
5
|
$("#invert").click(function(){ $("#ruleMessage [name='delModuleID']:checkbox").each(function(i,o){ $(o).attr("checked",!$(o).attr("checked")); }); }); |
6、获取选择项的值
|
1
2
3
4
5
6
7
8
|
var aa=""; $("#btn5").click(function(){ $("input[name='checkbox']:checkbox:checked").each(function(){ aa+=$(this).val() }) document.write(aa); }) }) |
7、遍历选中项
|
1
2
3
4
|
$("input[type=checkbox][checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出 alert($(this).val()); }); |
jquery checkbox用法汇总的更多相关文章
- jquery replace用法汇总
//只替换匹配到的第一个目标 var str="Visit Microsoft! Microsoft"document.write(str.replace(/Microsoft/, ...
- JQuery select,checkbox用法 文本框只能输入数字
记录一下,方便查找 a.文本框只能输入数字 onkeyup='this.value=this.value.replace(/\D/gi,"")' eg: <input typ ...
- jquery基础知识汇总
jquery基础知识汇总 一.简介 定义 jQuery创始人是美国John Resig,是优秀的Javascript框架: jQuery是一个轻量级.快速简洁的javaScript库.源码戳这 jQu ...
- jquery checkbox勾选取消勾选的诡异问题
jquery checkbox勾选/取消勾选的诡异问题jquery checkbox勾选/取消勾选的诡异问题 <form> 你爱好的运动是?<input type=&q ...
- jQuery $.each用法[转]
jQuery $.each用法 以下内容非原创,来自百度文库http://wenku.baidu.com/view/4796b6145f0e7cd18425368e.html 通过它,你可以遍历对象. ...
- jQuery数组处理汇总
jQuery数组处理汇总 有段时间没写什么了, 打算把jquery中的比较常用的数组处理方法汇总一下 $.each(array, [callback])遍历,很常用 1 2 3 4 5 6 7 8 ...
- JQuery Checkbox的change事件
JQuery Checkbox的change事件 参考 http://blog.csdn.net/hbhgjiangkun/article/details/8126981 $(functio ...
- jQuery 事件用法详解
jQuery 事件用法详解 目录 简介 实现原理 事件操作 绑定事件 解除事件 触发事件 事件委托 事件操作进阶 阻止默认事件 阻止事件传播 阻止事件向后执行 命名空间 自定义事件 事件队列 jque ...
- jquery cookie 用法
jquery cookie 用法 $.cookie("name","value","options") 当不设置options时,此coo ...
随机推荐
- 【BZOJ1038】【ZJOI2008】瞭望塔 [模拟退火]
瞭望塔 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 致力于建设全国示范和谐小村庄的H村村 ...
- 课下加分项目 MYPWD 20155335 俞昆
Mypwd 的解读与实现 20155335 linux下pwd命令的编写 实验要求: 1 .学习pwd命令 2 . 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 .实现my ...
- RabbitMq related
# RabbitMq related Integration of message queuing tools with systems is the usual solution to handle ...
- 20、redis和memcached比较?
1.Redis和Memcache都是将数据存放在内存中,都是内存数据库.不过memcache还可用于缓存其他东西,例如图片.视频等等: 2.Redis不仅仅支持简单的k/v类型的数据,同时还提供lis ...
- 控制 Cookie 的作用范围
默认时,网站的所有 Cookies 都一起被存储在客户端,并且所有 Cookies 连同网站的任何请求一起被发送到服务器.换句话说,网站中的每个页面都能够为网站获取所有的 Cookies.但是,你能够 ...
- Part2-HttpClient官方教程-Chapter3-HTTP状态管理
ps:近日忙于课设与一个赛事的准备....时间真紧啊~~ 最初,HTTP被设计为一种无状态的,面向请求/响应的协议,它并没有为跨越多个逻辑相关的请求/响应交换的有状态会话做出特殊规定.随着HTTP协议 ...
- LeetCode 20 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- Linux内核空间内存申请函数kmalloc、kzalloc、vmalloc的区别【转】
转自:http://www.th7.cn/system/lin/201606/167750.shtml 我们都知道在用户空间动态申请内存用的函数是 malloc(),这个函数在各种操作系统上的使用是一 ...
- rhel-server srpms iso
http://ftp.redhat.com/pub/redhat/linux/enterprise/7Server/en/ ftp://ftp.pslib.cz/pub/linux/redhat-cz ...
- OpenRCT2
https://github.com/OpenRCT2/OpenRCT2 https://github.com/LRFLEW/HRM-CCPU https://github.com/LRFLEW/Op ...