When using the jquery ICheck plugin, there is a problem when we use the normal JS full selection function 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 is fine for writing to the default checkbox, but will not work when using the Icheck plugin.
So what's the solution?
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 varCheckall = $ ('Input.all'); varCheckboxes = $ ('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 resolving the select issue, a new problem has been encountered, when the value of the selected checkbox is obtained, use: $ (this). attr (' checked '); get not the value ~, the egg hurts.
Finally after Google search, or in StackOverflow found the inspiration, to determine the Boolean value of the checkbox, using: $ (this). Is (': checked ');
The final code is resolved as follows:
$(". Ajax-delete"). Click (function () {varURL = $ ( This). attr ('Data-url'); varStr=""; varids=""; $("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);});
Extended:
1. Determine the selected number/length
var len = $ ("Input[name= ' id ']:checkbox"). Length;
From: Http://www.tuicool.com/articles/aANRBv
Official website: http://www.bootcss.com/p/icheck/
Full selection of Icheck and get value