Analysis of checkbox Total selection problem based on jquery _jquery

Source: Internet
Author: User

In this paper, we analyze the whole selection of checkbox based on jquery. Share to everyone for your reference, specific as follows:

The most recent development project encountered a very strange problem, that is, checkbox selection and selection of all
A framework for using jquery. has been the use of

Detects the selected checkbox
$ (' input[name= ' abc ']:checked '). each (function () {})

But when I found out that I needed a full selection, I used

$ (' input[name= "abc"]). attr (' checked ', true);
$ (' input[name= "abc"]). attr (' checked ', false);

, it works when it's first loaded, then clicks on it and only shows itself.
But when clicked, view the source code, attribute checked has been added to the
Baffled, the last search, the original is the Attr property for checked, he will not change the DOM style, will only change its property values, jquery provides a way to replace, the following can be

$ (' input[name= "abc"]). Prop (' checked ', true);
$ (' input[name= "abc"]). Prop (' checked ', false);

But then again, I couldn't detect which element was clicked when I was not fully selected, and then I made a fuss over name.

$ (' input[name= ' abc[]:checked '). Each (function (i) {});
or
$ (' input[name= ' abc[] '). Each (function (i) {
  var flag = $ (this). Prop (' checked ');
  if (flag) {
   //$ (this) is the selected element
 }
})

Solve the problem.

More interested readers of jquery-related content can view the site: "jquery form Operation Tips", "jquery switching effects and techniques summary", "jquery drag-and-drop effects and techniques summary", "JQuery Extended Skills Summary", " jquery Common Classic Effects Summary "jquery animation and special effects usage Summary", "jquery selector usage Summary" and "jquery common Plug-ins and Usage summary"

I hope this article will help you with the jquery program design.

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.