1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > HTML中让表单input等文本框为只读不可编辑的方法

HTML中让表单input等文本框为只读不可编辑的方法

时间:2024-04-01 03:52:20

相关推荐

HTML中让表单input等文本框为只读不可编辑的方法

方法1: οnfοcus=this.blur() 当鼠标放不上就离开焦点

[html]view plaincopy<inputtype="text"name="input1"value="中国"onfocus=this.blur()>

方法2:readonly

[html]view plaincopy<inputtype="text"name="input1"value="中国"readonly> <inputtype="text"name="input1"value="中国"readonly="true">

[html]view plaincopy方法3:disabled[html]view plaincopy<inputtype="text"name="input1"value="中国"disabled="true"> 完整的例子: [html]view plaincopy<inputname="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 style="ime-mode: disabled">

有两种方法:

第一:disabled="disabled"这样定义之后被禁用的 input 元素既不可用,也不可点击。

第二:readonly="readonly" 只读字段是不能修改的。不过,用户仍然可以使用 tab 键切换到该字段,还可以选中或拷贝其文本;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。