Jquery APIs provide the following methods to apply the disabled and readonly attributes to elements:
1. readonly
$ ('Input '). ATTR ("readonly", "readonly") // set the input element to readonly $ ('input '). removeattr ("readonly"); // remove the readonly attribute of the input element if ($ ('input '). ATTR ("readonly") = true) // determine whether the readonly attribute has been set for the input element. There are two methods to set the readonly attribute for the element and cancel the readonly attribute: $ ('input '). ATTR ("readonly", true) // set the input element to readonly $ ('input '). ATTR ("readonly", false) // remove the readonly attribute of the input element $ ('input '). ATTR ("readonly", "readonly") // set the input element to readonly $ ('input '). ATTR ("readonly", "") // remove the readonly attribute of the input element
2. Disabled
$ ('Input '). ATTR ("disabled", "disabled") // set the input element to disabled $ ('input '). removeattr ("disabled"); // remove the disabled attribute of the input element if ($ ('input '). ATTR ("disabled") = true) // you can determine whether the disabled attribute has been set for the input element. There are two methods to set the disabled attribute for the element and cancel the disabled attribute: $ ('input '). ATTR ("disabled", true) // set the input element to disabled $ ('input '). ATTR ("disabled", false) // remove the disabled attribute of the input element $ ('input '). ATTR ("disabled", "disabled") // set the input element to disabled $ ('input '). ATTR ("disabled", "") // remove the disabled attribute of the input element
3. About checkbox (check whether a group of checkbox values are determined by the same name)
Because the checkbox itself does not provide the readonly method, and disabled will become gray, so we found two methods.
Method 1: the checkbox does not have the readonly attribute. If the Disabled = "disabled" attribute is used, the checkbox will become gray. The user is disgusted with this style so that it can be read-only: set its onclick = "Return false" js to checkbox. onclick = function () {return false ;}; Method 2: <SCRIPT src = "demo3.1/jquery-1.4.2.min.js" type = "text/JavaScript"> </SCRIPT> <script language = "JavaScript"> $ (function () {$ ("input [type = 'checkbox']"). click (function () {This. checked =! This. Checked ;}); </SCRIPT>
4. Read-Only settings for select
We recommend that you use disabled instead of using the checkbox method.