How jQuery checks whether the check box is checked and an example

Source: Internet
Author: User

To enable this function today, you can assign a value to the input form when the check box is selected, and clear the form value when the check box is canceled.

Effect
 
Implementation source code: cyfID is the id of the check box
Copy codeThe Code is as follows:
$ ("# CyfID"). click (function (){
Var ischeck = $ (this). attr ("checked ");
If (ischeck = undefined ){
// Clear the input box
Alert ("");
} Else {
// Assign a value to the input box
Alert ("qq ");
}
});

Implementation principle: when the check box is checked, $ (this). attr ("checked") is checked and undefined is not checked.

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.