Full selection of Icheck and get value

Source: Internet
Author: User

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

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.