使文本框不可编辑的方法

来源:互联网 发布:淘宝排名监控 编辑:程序博客网 时间:2024/06/07 06:11

      很多时候,有的数据有查看和编辑两种状态,在查看状态下,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使<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>

 一下分别是readonly和disabled的效果截图:

 readonly:

 disabled:

 这虽然很简单,但有时候很有用!

原创粉丝点击