How to set the checkbox check box to read-only and the checkbox check box to read-only

Source: Internet
Author: User

How to set the checkbox check box to read-only and the checkbox check box to read-only

How to set the checkbox check box to read-only:
The check box checkbox does not have the readOnly attribute, but if it is set to unavailable, that is, its disabled = "disabled", the checkbox value will not be sent, and the appearance is gray, the following describes how to simulate the read-only Status of check boxes.
I. Native javascript code:

CkObj. onclick = function () {return false ;}

That is, the default action of canceling the action with return false is used. When you click the check box, the default action is to select or deselect the check box.
Ii. jQuery code achieves this effect:

$ (Function () {$ ("input [type = 'checkbox']"). click (function () {this. checked =! This. checked ;})})

The above Code also meets our requirements. The method is very simple: Set the checked attribute value of the check box to the original state ,! This. checked returns the opposite status of the check box after it is clicked. For example, if it is selected before it is clicked, It is not selected after it is clicked, and the opposite status is selected.
Related reading:
1. [type = 'checkbox'] refer to [attribute! = Value] selector 1 chapter.
2. For more information about the checked attributes, see section checkbox. checked attributes in javascript.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9484.

For more information, see: http://www.softwhy.com/jquery/

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.