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/