I do not know why the previous JS write the full selection and anti-selection function can not be used, after the Chrome browser console view, found that it does not work, but the style has not changed. First, just put the HTML code, omit the other code, only contains a checkbox:
<!--lang:html--<label class= "checkbox" > <input class= "states" type= "checkbox" Name= "IDs" Val ue= "1"/> </label> <label class= "checkbox" > <input class= "states" type= "checkbox" Name= "IDs "Value=" 2 "/> </label> <label class=" checkbox "> <input class=" states "type=" checkbox "Name = "IDs" value= "3"/> </label>
But the source code you see on the Chrome browser console is a bit more labeled:
<label class= "checkbox" > <div class= "Checker" > < span> < Input class= "states" type= "checkbox" name= "IDs" value= "1" /> <span> </div> </label> <label class= "checkbox "> <div class=" > "Checker" <span> <input class= "states" type= "checkbox" name= " IDs " value=" 2 " /> <span> </div> </label> < label class= "checkbox" > <div class= "Checker" > <span> <input class= "states" type= "checkbox" name= "IDs" value= "3" /> <span> </div> </label>
CheckBox out of the two-layer label, and when the,<span> tag added a style <span class= "checked", and then did not notice, so write JS:
function SelectAll () {$ ("input[type= ' checkbox ']"). each (function () {$ (this). attr (' checked ', true); $ (this). addclass (' checked '); });}
Later on, the $ (this) is the CheckBox object, which should be the parent tag of the checkbox <span> add style, so it changes to:
function SelectAll () {$ ("input[type= ' checkbox ']"). each (function () {$ (this). attr (' checked ', true); $ (this). Parents ('. CheckBox '). Find (' span '). addclass (' checked '); });} function Invertselect () {$ ("input[type= ' checkbox ']"). each (function () {if ($ (). attr (' checked ')} {$ (this). attr (' Checked ', false); $ (this). Parents ('. CheckBox '). Find (' span '). Removeclass (' checked ');} else {$ (this). attr (' checked ', true); $ (this). Parents ('. CheckBox '). Find (' span '). addclass (' checked ');} });}
This will be OK.
Bootstrap Select and reverse selection of checkbox in Open source package