js notes - how to set the text box to be non-editable

JS realizes that the text box cannot be edited
 Method 1: onfocus=this.blur() When the mouse cannot be placed, leave the focus
<input type="text" name="input1" value="China" onfocus=this.blur()> 
method 2:readonly  <input type="text" name="input1" value="China" readonly>  <input type="text" name="input1" value="China" readonly="true"> 
Method 3: disabled  < input type="text" name="input1" value="Chinese" disabled <input type="text" name="input1" value="Chinese" disabled="true">


Disabled input elements defined with disabled="disabled" are neither usable nor clickable.

readonly="readonly" Read-only fields cannot be modified.


js dynamically implements the uneditable state of the text box

Two methods:

 $("#id").attr("readOnly",false); not editable, you can pass values

 $("#id").attr("disabled",false); cannot be edited and cannot be passed by value

Note that the O in readOnly is capitalized

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325956419&siteId=291194637