bootstrap iCheck插件 全选和获取value值的解决方法
在使用jQuery iCheck 插件的时候遇到了一个问题,就是当我们使用普通的js全选功能无效了。
$("#checkall").click(function(){if(this.checked){$("input[name='checkname']").each(function(){this.checked=true;});}else{$("input[name='checkname']").each(function(){this.checked=false;});}});
这样来写对默认的checkbox框没问题,但是当使用iCheck 插件后将无效。
那么该怎么解决呢?
最后是在stackoverflow 找到的解决方法:
地址是这里:http://stackoverflow.com/questions/17820080/function-select-all-and-icheck
//全选获取数值varcheckAll=$('input.all');varcheckboxes=$('input.check');checkAll.on('ifCheckedifUnchecked',function(event){if(event.type=='ifChecked'){checkboxes.iCheck('check');}else{checkboxes.iCheck('uncheck');}});checkboxes.on('ifChanged',function(event){if(checkboxes.filter(':checked').length==checkboxes.length){checkAll.prop('checked','checked');}else{checkAll.removeProp('checked');}checkAll.iCheck('update');});
在解决了全选问题后,又遇到了一个新的问题,获取选中的checkbox的value的时候,使用:$(this).attr('checked');获取不到值了~,蛋疼。
最后几经Google搜索,还是在stackoverflow 找到了启发,判断checkbox的布尔值,使用 :$(this).is(':checked');
最后代码的解决方法如下:
$("#manager_click").parent().siblings(".btn-primary").click(function(){//varurl=$(this).attr('data-url');varstr="";varids="";$("#manager_tabletd.check-mailinput").each(function(){if(true==$(this).is(':checked')){str+=$(this).parent().parent().siblings(".mail-ontact").text()+",";}});if(str.substr(str.length-1)==','){ids=str.substr(0,str.length-1);}console.log(str);console.log(ids);});
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。