HTML中让表单input等⽂本框为只读不可编辑的⽅法
html表单只能输入数字
有时候,我们希望表单中的⽂本框是只读的,让⽤户不能修改其中的信息,如使<input type="text" name="input1" value="中国"> 的内容,"中国"两个字不可以修改。实现的⽅式归纳⼀下,有如下⼏种。
⽅法1: onfocus=this.blur() 当⿏标放不上就离开焦点
<input type="text" name="input1" value="中国" onfocus=this.blur()>
⽅法2:readonly
<input type="text" name="input1" value="中国" readonly>
<input type="text" name="input1" value="中国" readonly="true">
⽅法3: disabled
<input type="text" name="input1" value="中国" disabled="true">
完整的例⼦:
<input name="ly_qq" type="text" tabindex="2" onMouseOver="this.className='input_1'"
onMouseOut="this.className='input_2'" value="123456789" disabled="true" readOnly="true" />
disabled="true"此果⽂字会变成灰⾊,不可编辑。
readOnly="true"⽂字不会变⾊,也是不可编辑的
css屏蔽输⼊:<input >
有两种⽅法第⼀:disabled="disabled"这样定义之后被禁⽤的 input 元素既不可⽤,也不可点击。第⼆:readonly="readonly"只读字段是不能修改的。不过,⽤户仍然可以使⽤ tab 键切换到该字段,还可以选中或拷贝其⽂本;