jQuery输入文件单击方法,IE上的访问被拒绝 [英] jQuery input file click method and access denied on IE
问题描述
我正在尝试仅使用一个按钮作为输入文件,它在Firefox,Chrome,Safari和IE中均能正常工作,但是在IE中却无法......提交表单时,我总是会遇到访问被拒绝"的情况.
I'm trying to use only a button as input file, it works fine in Firefox, Chrome, Safari but not in IE... I always get 'access denied' when submitting the form.
代码:
$('#input_file').click();
真的有解决方案吗?我在Google上浪费了大约2个小时,但找不到.
Is there a real fix for it? I wasted about 2 hours on google but I can't find it.
推荐答案
我找到了解决之道. 将按钮包裹在标签标签中,如下所示:
I found a way around it. Wrap the button in label tags like this:
<label for="fileinput"><div class="button">Upload file</div></label>
<form>
<input id="fileinput" name="file" type="file">
</form>
单击标签将触发文件输入,而不会在Internet Explorer中使表格无效 (在IE9和IE10中测试)
Clicking the label will trigger the file input without invalidating the form in internet explorer (tested in IE9 & IE10)
将此代码提供给IE,并保留其他浏览器的javascript解决方案.单击标签后,Firefox不会触发文件输入字段.
serve this code to IE and keep the javascript solution for other browsers. Firefox will not trigger the file input field when the label is clicked.
这篇关于jQuery输入文件单击方法,IE上的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!