JS实现全选与取消 Jquery判断checkbox是否被选中
1.JS实现checkbox全选与取消
<body>
<input type="checkbox" name="select_all"/>11
<input type="checkbox" name="select_all"/>22
<input type="checkbox" name="select_all"/>33
<input type="checkbox" name="select_all" onClick="selAll(this)">全选
</body>
JS代码:
function selAll(obj)//全选与实现全选取消
{
var o=document.getElementsByName("select_all");
for(var i=0;i<o.length;i++)
{
if(obj.checked==true)
{
o[i].checked=true;
} else{
o[i].checked=false;
}
}
}
2.Jquery判断checkbox是否被选中
在html的checkbox里,选中的话会有属性checked="checked"。
如果有一个checkbox被选中,alert这个checkbox属性"checked"的值
alert($"#xxx".attr("checked")),会打印出"true",而不是"checked"!
如果没被选中,打印出的是"undefined"。
if($"#xxx".attr("checked")=="true") //这样是错误的
jQuery的API手册,attr(name)的返回值是object。所以,应该是
if($("#xxx").attr("checked")==true)。
判断这个值 $("input[name='weibo_count']").attr("checked"); 这样也行
$("#btn1").click(function(){
$("[name='checkbox']").attr("checked",'true');//全选
})
$("#btn2").click(function(){
$("[name='checkbox']").removeAttr("checked");//取消全选
})
JS实现全选与取消 Jquery判断checkbox是否被选中的更多相关文章
- jQuery 判断checkbox是否被选中 4种方法
下午写JS验证,有一个需求需要判断 checkbox是否被选择,查阅相关资料后,总结以下4种方法,分享给大家. <!DOCTYPE html> <html lang="en ...
- js和jquery判断checkbox是否被选中
js判断: if(document.getElementById("checkboxID").checked){ alert("checkbox is checked&q ...
- jq 全选和反选以及判断那条被选中
<body><div><input type="checkbox" id="a" />全选</div><d ...
- JS实现全选,取消全选,正常选择
//点击选择方法 onUserIdsChange(selVal) { if (this.form.groupUserIds.includes(-1) && !this.isSelect ...
- Jquery判断checkbox是否被选中
jQuery中: $("input[type='checkbox']").is(':checked') 返回true或false 1.attr()方法 设置或者返回备选元素的值 ...
- jquery 判断checkbox是否被选中问题
1.jquery库2以上 $("#checkbox_check").click(function(){ alert($(this).prop("checked" ...
- 每天学一点-Jquery判断checkbox是否为选中状态
if ($("#ctl00_ContentPlaceHolder1_IsLimitedService").attr("checked") ==true)
- 前端之 JS 实现全选、反选、取消选中
需求 制作如下可选表格,实现“全选”.“反选”.“取消”功能 代码示例 <!DOCTYPE html> <html lang="zh-CN"> <he ...
- python: jquery实现全选 反选 取消
引入这个jquery-1.12.4.js jquery实现全选 反选 取消 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitio ...
随机推荐
- BZOJ3714 [PA2014]Kuglarz 【最小生成树】
题目链接 BZOJ3714 题解 我们如果知道了所有的数,同样就知道了所有的前缀和 相反,我们如果求出了所有前缀和,就知道了所有的数,二者是等价的 对于一个区间\([l,r]\)如果我们知道了前缀和\ ...
- AOJ.850 电缆公司的烦恼 (二分+枚举)
AOJ.850 电缆公司的烦恼 (二分+枚举) 题意分析 从[1,average]二分枚举长度即可,由于保留2位小数,可以将数据扩大10^2倍后后枚举,输出时除100即可. 代码总览 #include ...
- SpringBoot-配置文件属性注入-3种方式
配置文件: datasource.username = admin datasource.url = /hello/world 方式一: @Value 前提: <!-- JavaBean处理工具 ...
- Generating Sets 贪心
H - Generating Sets Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- HBase客户端访问超时的多个因素及参数
在一个需要低延时响应的hbase集群中,使用hbase默认的客户端超时配置简直就是灾难. 但是我们可以考虑在客户端上加上如下几个参数,去改变这种状况: 1. hbase.rpc.timeout: RP ...
- JSTL 入门: 表达式语言
转载自:http://www.ibm.com/developerworks/cn/java/j-jstl0211/ JavaServer Pages(JSP)是用于 J2EE 平台的标准表示层技术.J ...
- ZooKeeper食谱(八)
使用ZooKeeper构造高级别应用的指南 在这个文章中,你将会发现使用ZooKeeper来实现高级别功能的指南.所有的它们在客户端上被实现而不需要ZooKeeper特别的支持.希望社区将注意到这些约 ...
- String.replaceAll()方法替换字符串中的反斜杠(\)
replaceAll()方法实际是采用正则表达式的规则去匹配的. 在regex中"\\"表示一个"\",在java中一个"\"也要用&quo ...
- RabbitMQ与Spring集成
RabbitMQ服务端安装: https://blog.csdn.net/hzw19920329/article/details/53156015 与Spring集成 https://www.cnbl ...
- Informatica _组件使用介绍及优化
转载 http://blog.csdn.net/yongjian1092/article/details/52588434 有空自己会写一个关于这方面的文章.