The BootStrap iCheck plug-in Selects all and obtains the value.
When using the jQuery iCheck plug-in, we encountered a problem, that is, when we use the common JavaScript all-selection function, it is invalid.
$("#checkall").click(function(){if(this.checked){$("input[name='checkname']").each(function(){this.checked=true;});}else{$("input[name='checkname']").each(function(){this.checked=false;});}});
In this way, it is okay to write the default checkbox box, but it will be invalid when the iCheck plug-in is used.
How can this problem be solved?
The solution found in stackoverflow is as follows:
Address is here: http://stackoverflow.com/questions/17820080/function-select-all-and-icheck
// Obtain the value var checkAll = $ ('input. all '); var checkboxes = $ ('input. check'); checkAll. on ('ifchecked ifunchecked', 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 ');});
After the full selection problem is solved, a new problem is encountered. When obtaining the value of the selected checkbox, use: $ (this ). attr ('checked'); the value cannot be obtained ~, It hurts.
In the last few Google searches, I found the inspiration in stackoverflow to determine the Boolean value of the checkbox, using: $ (this). is (': checked ');
The final solution of the Code is as follows:
$(".ajax-delete").click(function(){var url = $(this).attr('data-url');var str="";var ids="";$("input[name='id']:checkbox").each(function(){if(true == $(this).is(':checked')){str+=$(this).val()+",";}});if(str.substr(str.length-1)== ','){ids = str.substr(0,str.length-1);}console.log(ids);});
The above section describes how to select all the BootStrap iCheck plug-ins and how to obtain the value. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!