_ Javascript tips

Source: Internet
Author: User
Sometimes you only want to tell the user that you can check the box, rather than asking the user to check it here (for example, on the information display page). In this case, you need to set the check box to read-only, the specific implementation method is as follows: In Web development, sometimes some check boxes (checkbox) need to be displayed, indicating that this area can be checked, however, sometimes you only want to tell the user that "this place can be checked" and do not want the user to check it here (for example, on the information display page ), in this case, you need to set the check box to read-only.

When it comes to read-only, it is easy to think of using the readonly attribute, but for the check box, this attribute is different from the expected result. The reason is thatThe readonly attribute is associated with the value Attribute of the page element (for example, in textbox, the text content of the input box cannot be modified after readonly is set), and the check box check/cancel does not change its value attribute, the changed status is only a checked state.Therefore, if readonly is set for the checkbox, you can still select/cancel it. The effect is as follows:

Readonly = "readonly"/>
Option
Option B
Option c
Option
Option B
Option c

Similar to readonly, there is also a disabled attribute, which sets the page element to unavailable, that is, you cannot perform any interactive operations (including the value attribute and the checked status cannot be modified ). The effect is as follows:

Disabled = "disabled"/>
Option
Option B
Option c
Option
Option B
Option c

We can see from the above that neither readonly nor disabled has achieved the expected results. Since it cannot be directly implemented, we can modify it to simulate the implementation. The Code is as follows:

Onclick = "return false ;"Checked = "checked"/>
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.