清除Internet Explorer中的文件输入框 [英] Clearing file input box in Internet Explorer

查看:104
本文介绍了清除Internet Explorer中的文件输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个文件上传框和一个清除按钮。当我按下清除按钮时,我想要清除文件上传框中的文本。

以下在Fi​​refox中工作,但不在IE中在那里停留)。是否有解决方法?

  $(#clear)。click(function(){
$ (#attachment)。val();
//document.myform.attachment.value =;
})

HTML:

 < form name =myform> ; 
< input type =filename =attachmentid =attachment/>
< / form>
< br />< button id =clear>清除附件< / button>

jsFiddle

解决方案

它只读于 IE8开始,所以你不能清除它。围绕此安全功能的最简单的方法是将元素替换为副本。



编辑发现以前的答案, ! 清算< input type ='file'/>使用jQuery


I have an file upload box and a clear button on my page. When I press the clear button, I want the text in the file upload box to be cleared.

The following works in Firefox, but doesn't in IE (the text stays there). Is there a workaround for this?

$("#clear").click( function() {
    $("#attachment").val("");
    //document.myform.attachment.value = "";
})

HTML:

<form name="myform">
    <input type="file" name="attachment" id="attachment" />
</form>
<br /><button id="clear">Clear Attachment</button>

jsFiddle

解决方案

It's readonly in IE8 onwards, so you can't clear it. The simplest way around this security feature is to replace the element with a copy.

Edit Found a previous answer to this that suggests the same approach! Clearing <input type='file' /> using jQuery

这篇关于清除Internet Explorer中的文件输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆