Discuz教程网

<input text/> 禁止用户输入

[复制链接]
authicon dly 发表于 2011-3-26 15:06:28 | 显示全部楼层 |阅读模式
在写页面的时候,经常会遇到对用户输入进行合法性&正确性验证的情况,主要原因就是因为用户的输入不规范。所以得想个办法让这种情况不要出现——限制用户输入,具体可以有如下2种实现:
1.使用 contenteditable 属性
<input type="text" id="text_1" contenteditable="false" />

2.用脚本事件拦截用户输入
<input type="text" onkeydown="return false" onkeyup="return false" oncontextmenu="return false">

局限性:目前这两种方式在FireFox上无效。






上一篇:input禁止键盘及中文输入,但可点击!
下一篇:IE6显示iframe页面空白的解决办法
authicon  楼主| dly 发表于 2011-3-26 15:17:38 | 显示全部楼层

input 禁止输入

方法一:推荐

<input type="text" readonly>

<input type="text" disabled>

方法二:在ie可以完全屏蔽input 输入 firefox上面去掉了光标 还是可以输入字符

<input type="file" id="file1" contenteditable="false" />

方法三:只能屏蔽中文输入法,可以复制到input [ typt=text ] 里面

<input style="ime-mode: disabled">

方法四:

<input type="file"  style="ime-mode:disabled;"  id="ctrct_cnts" name="ctrct_cnts"/>

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 05:37

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表