大鱼

使input type="file" 不可编辑

使input type="file" 不可编辑
今天在做项目的时候,遇到上传文本框的问题,
<input type="file" size="100" name="photoupload" />
在firefox中,该控件产生的文本框是默认不可编辑的,但是在IE下,该文本框可编辑,
根据用户需要,此文本框应为不可编辑。
但是直接将其设置为“readonly”或者“disabled”后,对应的浏览按钮也无法使用了。所以此法不通。

在网上搜索了一些资料,主要有以下几种方法:
1.变通处理:
<input type=file id=a1 style="visibility:hidden">
<input id=a2 type=text readonly>
<input type=button value=浏览 onclick="a1.click(); a2.value= a1.value">
2.增加如下属性:
contenteditable="false"

 实例代码:

<input type="file" style="width: 446px" id="ptlFile" contenteditable="false"/>

对比一下,第二种简单方便,问题解决。

posted on 2009-03-13 23:25 大鱼 阅读(651) 评论(1)  编辑  收藏 所属分类: javascript

评论

# re: 使input type="file" 不可编辑 2010-08-07 13:28 龙心

thank you very much!  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: