首页 > 其他 > 详细

boostrap checkbox全选

时间:2016-02-26 18:26:54      阅读:215      评论:0      收藏:0      [点我收藏+]
<div class="box-content" id="list">
    <input  id=check-All type=checkbox onclick="checkAll()">
    <input type=checkbox  name="keys" id="keys">
<div>
function checkAll(){
         var sp=$("#check-All").is(:checked);//判断是否选中
         var repayIds=$("#repayIds").val();//获取变量
     var box = document.getElementsByName("keys");//获取所有checkbox

if(sp==false){   $("#list :checkBox,check-All").parent(span).removeClass("checked");
        //id为"list"内的div里面的checkBox和id="check-All"的checkBox,取消选中效果

$(
"#list :checkBox,check-All").attr("checked",false);           
        //id为"list"内的div里面的checkBox和id="check-All"的checkBox,取消选择
for (var i=0;i<box.length;i++ ){ repayIds=repayIds.replace(box[i].value+"," ,"");       
              //去掉选择的值 } }
else{ $("#list :checkBox,check-All").parent(span).addClass("checked");  
          //id为"list"内的div里面的checkBox和id="check-All"的checkBox,变为选中效果

$(
"#list :checkBox,check-All").attr("checked",true);          
        //id为"list"内的div里面的checkBox和id="check-All"的checkBox,变为选中

for (var i=0;i<box.length;i++ ){ if(!repayIds.contains(box[i].value)){              
              //拼接选中的值,","隔开 repayIds
+=box[i].value+"," } } } $("#repayIds").val(repayIds);                            
      //存入变量中 }

 

boostrap checkbox全选

原文:http://www.cnblogs.com/wangzhuxing/p/5221162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!