![](/img/trans.png)
[英]dataTables form won't submit correctly in Internet Explorer
[英]Input submit didn't submit form with jquery in Internet Explorer
我创建了HTML和jQuery代码以使用jQuery提交表单,并且该表单在除Internet Explorer之外的所有浏览器中均可使用。
HTML:
<form name="file_upload" id="file_upload" action="<?php echo base_url(); ?>projects/file" enctype="multipart/form-data" method="POST">
<a class="button" onclick="document.getElementById('file-upload-input').click(); return false;"><span class="plus"></span>Upload File</a>
<input id="file-upload-input" name="upload" type="file" style="display:none;">
<input id="submit-button" name="submit" type="submit" value="Upload" style="display:none;">
</form>
jQuery的
$(document)
.on('change', '#file-upload-input', function(){
$('#submit-button').click();
})
编辑 :我也尝试过:
$(document)
.on('change', '#file-upload-input', function(){
$("#file_upload").submit();
})
但是输入提交并不仅在Internet Explorer中提交表单。
尝试这个。
$(document)
.on('change', '#file-upload-input', function(){
$("#file_upload").submit();
})
更改:
$('#submit-button').click();
至:
$('#file_upload').submit();
应该可以。
在IE中对“更改”事件使用委托事件方法时,您可能会遇到问题(因为它不支持冒泡委托依赖的事件)。
尝试将onchange处理程序直接绑定到文件输入:
$('#file-upload-input').on('change', function(){
$("#file_upload").submit();
})
我认为事件传递限制了javascript触发的某些操作。 因此,您应始终使用由浏览器触发的原始事件,在您的情况下,我们可以使用CSS使文件上传输入透明,并覆盖到“ a”按钮:
<input id="file-upload-input" name="upload" type="file" style="
width: 88px;
position: absolute;
left: 0;
opacity: 0;
filter:alpha(opacity=0)
">
如果可行,您可以删除绑定到“ a”节点的onclick事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.