Jquery binds a single worker checkbox with a click event _ jquery

Source: Internet
Author: User
Sometimes you may need to use scripts to bind events to some forms: for example, Jquery binds a click event to a single-sheet checkbox, And I search and sort out some common skills, for more information, see section 1. Suppose you have the following html code.

The Code is as follows:






Selected events (modify the previous background based on the selected conditions ):

The Code is as follows:


Var $ test_image_check_box_click = function (){
If ($ (this). attr ("checked") = "checked "){
Certificate (this).parent().css ({"background": "# dcf4fc "});
}
Else {
Certificate (this).parent().css ({"background": "# fcf7c7 "});
}
Check_all_imagezz ();
}


Bind event:

The Code is as follows:


$ (# Checkbox-518). click ($ test_image_check_box_click );


2. Assume that there are many parallel dd tags in html. Each dd tag has a checkbox and the class name is imagezz. Each checkbox is bound to a preset $ test_image_check_box_click event.

The Code is as follows:


$ (Document). ready (function (){
$ (". Imagezz"). click ($ test_image_check_box_click );
}

Related Article

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.