When using the jQuery iCheck plug-in, we encountered a problem, that is, when we use the ordinary js selection all 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;});}});This will be fine to write the default checkbox box, but it will be invalid when using the iCheck plugin.
So how to solve it?
Finally, the solution found in stackoverflow:
The address is here: http://stackoverflow.com/questions/17820080/function-select-all-and-icheck
//Select all to get 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 solving the selection all problem, I encountered a new problem. When getting the selected checkbox value, use: $(this).attr('checked'); it cannot get the value~, it hurts.
After Google searches, I found inspiration in stackoverflow to determine the boolean value of checkbox, using: $(this).is(':checked');
The solution to the final 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 is the solution to select all BootStrap iCheck plug-ins and obtain value values introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!