Native js operations checkbox use document. getElementById to implement _ javascript skills

Source: Internet
Author: User
Js checkbox operation I suggest using document. getElementById (checkbox_id). checked. jquery is not recommended for checkbox operations. If you are interested, do not miss the checked attribute of jquery and checkbox.

1. After the page is loaded successfully, click to select or deselect the checkbox. The checked attribute in the checkbox attribute does not change based on whether or not the checkbox is selected.

2. The onchange or onclick method in the checkbox uses the attr method of jquery to obtain the checked. The value of the checked attribute is irrelevant to whether it is hooked.

3. Use document. getElementById ("checkbox_id"). The value obtained by checked is the same as that obtained by WYSIWYG.

4. Use $ ("# checkbox_id"). attr ("checked") to obtain Checked in 1 to, not WYSIWYG

5. $ ("# checkbox: checked") is used to obtain the checkbox on the hook.

6. document. getElementById ("checkbox_id"). checked = true. The checked attribute in the control is not displayed.

7. $ ("# checkbox_id"). attr ("checked", true), The checked attribute in the control is displayed. What you see is displayed, and the Code also changes.

Js operation checkbox I suggest using document. getElementById ("checkbox_id"). checked, jquery operation checkbox is really uncomfortable
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.