Bootstrap Select and reverse selection of checkbox in Open source package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.