站长网 教程 HTML中让表单input不可编辑的方法

HTML中让表单input不可编辑的方法

HTML中让表单input不可编辑的方法,有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使input type=text name=input1 value=中国 的内容,中国两个字不可以修改。表单input不可编辑的方法实现的方式归纳一下,有如下几种。 input不可

 HTML中让表单input不可编辑的方法,有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使<input type="text" name="input1" value="中国"> 的内容,"中国"两个字不可以修改。表单input不可编辑的方法实现的方式归纳一下,有如下几种。
 
input不可编辑,方法1: onfocus=this.blur() 当鼠标放不上就离开焦点
 
 
  <input type="text" name="input1" value="中国" onfocus=this.blur()>
 
input不可编辑,方法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" 此处文字会变成灰色,input不可编辑。
 
  readOnly="true" 文字不会变色,也是不可编辑的
 
css屏蔽输入:<input style="ime-mode: disabled">
 
  令input不可编辑有两种方法第一:disabled="disabled"这样定义之后被禁用的 input 元素既不可用,也不可点击。第二:readonly="readonly" 只读字段是不能修改的。不过,用户仍然可以使用 tab 键切换到该字段,还可以选中或拷贝其文本。

本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/video/2021/1201/31979.html

作者: dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。
联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部