`

input type=file 禁止让用户手动输入

阅读更多
1. 取代法

       使用隐藏的<input type="file"/>控件,然后用一个只读的文本框和一个按钮来模拟<input type="file"/>的功能。

<input type="file" name="file" onpropertychange="file1.value=this.value" style=display:none/>   
<input type="text" name="file1" readonly/>   
<input type="button" value="浏览" id="button1" name="button1" onclick="file.click()"/>

2. 使用脚本事件限制控件输入

       将<input type="file"/>控件的鼠标右键菜单、按键事件限制住,不让用户有机会输入。
<input type="file" onkeydown="return false" onkeyup="return false" oncontextmenu="return false">


3. 使用contenteditable属性

       使用该属性可以有效地限制用户在<input type="file"/>控件中手动输入内容,而只能通过文件选择对话框选择文件。

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






只能输入数字的Input
<input
onkeypress="return (/^(-?\d+)(\.\d+)?$/.test(String.fromCharCode(event.keyCode))) || ( /^(-?\d+)$/.test(this.value)  )  "
onpaste="return !clipboardData.getData('text').match(/\D/)"
ondragenter="return false"
style="ime-mode:Disabled"
>




分享到:
评论
1 楼 sdh88hf 2011-06-02  
概括的很好,谢谢分享

相关推荐

Global site tag (gtag.js) - Google Analytics