首页 > 学院 > 开发设计 > 正文

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

2019-11-17 02:07:53
字体:
来源:转载
供稿:网友

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

Posted on 2015-05-29 14:39 haishu 阅读(...) 评论(...) 编辑 收藏

1. 替代法

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

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

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

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

<inputtype="file"onkeydown="returnfalse"onkeyup="returnfalse"oncontextmenu="returnfalse">

3. 使用contenteditable属性

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

<inputtype="file"id="file1"contenteditable="false"/>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表