在以前的文章中提到了jquery全选/反选checkbox,今天分享一下js checkBox的全选,反选,与赋值。
//js 数值是否在数组中 Array.prototype.in_array = function(e){ for(i=0;i<this.length;i++){ if(this[i] == e) return true; } return false; } //js数组index Array.prototype.find_str=function(string){ var str = this.join(""); return str.indexOf(string); } var houseIds=new Array(); $("#chebox-list-all").click(function(){ if($("#chebox-list-all").attr("checked")){ $("[name='checkboxes']").attr("checked",'true');//全选 增加id var ids = document.getElementsByName('checkboxes'); var value = new Array(); for(var i = 0; i < ids.length; i++){ if(ids[i].checked) houseIds.push(ids[i].value); } alert(houseIds); }else{ $("[name='checkboxes']").removeAttr("checked");//反选 删除Ids houseIds=[]; alert(houseIds); } }) //单选增加id function check(obj){ if(!houseIds.in_array(obj.value)){ houseIds.push(obj.value); alert(houseIds); }else{ var index=houseIds.find_str(obj.value); houseIds.splice(index, 1) alert(houseIds); } }
参考:
[jquery checkbox radio a div 设置不可用/变灰的方法总结]
[jquery mobile Checkbox动态添加刷新及事件绑定]
标签:js javascript js checkBox js checkBox全选 js checkBox赋值 jquery
未注明转发、原文均为本站原创。分享本文请注明 原文链接 !
[基于html5、js的超强报表控件Echarts系列教程(1)-与其他报表的区别和介绍]
[基于html5、js的超强报表控件Echarts系列教程(2)-使用及环境部署]
[基于html5、js的超强报表控件Echarts系列教程(3)--事件使用]
[Echarts asp.net+ashx项目部署及代码实例(附demo)]
[echarts教程-asp.net+ashx实现堆积柱状图说明及demo下载]
[ECharts教程--基于力导向布局图功能更完善的人物关系图插件扩展开发(1)]
[ECharts--基于力导向布局图功能更完善的人物关系图插件扩展-节点样式和点击事件]
微信扫一扫,徜徉悠嘻网,您的休闲乐园
技术交流群:346717337
投稿:suchso@vip.qq.com
专业专注:企业网站门户/微网站/微商城/CMS系统/微信公众号运营/付费问题咨询