Jquery checks whether the checkbox (check box) is selected.

Source: Internet
Author: User
Many friends now like jquery, so many table judgments are based on jquery, but the implementation method is different from the javascript native code. For more information about checkbox judgments, see. The Code is as follows:


// Check whether the selected return true and no return false are selected.
Function mycheckbox (){
Var falg = 0;
$ ("Input [name = 'soft [] ']: checkbox"). each (function (){
If ($ (this). attr ("checked ")){
Falg + = 1;
}
})
If (falg> 0)
Return true;
Else
Return false;
}


This is a good method.
The following function is a supplement to the above:

The Code is as follows:


This is the writing method. Jq1.42.
Next, we recommend that you process the logic.
Function mycheckbox (){
Var falg = 0;
$ ("Input [name = 'soft [] ']: checkbox"). each (function (){
If ($ (this). attr ("checked ")){
Falg = 1;
Return false;
}
})
If (falg> 0)
Return true;
Else
Return false;
}


Below is a simple judgment
Jquery core judgment statement

If ($ ('input: checkbox'). attr ("checked") = true)

Everyone knows that in html, if a check box is selected as checked = "checked ".
However, if jquery alert ($ ("# id"). attr ("checked") is used, you will be prompted to be true instead of checked.
So many friends judge if ($ ("# id "). attr ("checked") = "true") This is incorrect. It should actually be if ($ ("# id "). attr ("checked") = true)

The example contains several functions.





Code

The Code is as follows:





New Document


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.