How to set the CheckBox check box to read-only

Source: Internet
Author: User

How to set the CheckBox check box to read-only:
check box checkbox does not have the ReadOnly property, but if it is set to not be available, that is, its disabled= "disabled", the checkbox value is not sent, and the appearance is grayed out, here is how to simulate the read-only state of the implementation check box.
One. Native JavaScript code:

ckobj.onclick=function() {  returnfalse;}

That is, using return False to cancel the default behavior of the action, when the check box is clicked, the default behavior is to select or uncheck.
Two. The jquery code achieves this effect:

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

The above code also implements our requirements, the method is very simple is to set the check box checked property value to the original state,! this.checked return is the check box is clicked on the opposite state, for example, before the click is selected, then the click is not selected, the opposite state is also selected.
Related reading:
1.[type= ' checkbox '] can refer to the [Attribute!=value] selector section of jquery .
2.checked properties can be found in the Checkbox.checked Properties section of JavaScript .

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

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

How to set the CheckBox check box to read-only

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.