在Internet Explorer中动态创建文件输入

Kie*_*iel 3 javascript internet-explorer file-upload cross-browser

单击我的自定义按钮后,下面的代码会动态创建一个文件输入,生成一个文件输入,其名称为photo [],id为photo'x'(x为变量).除了全能的IE之外,所有浏览器的代码都能正常运行.在IE中我可以单击我的自定义上传按钮添加文件,当我提交表单时,文件输入将被清除.它将提交表单,但文件输入将为空白.但它适用于其他浏览器.

这是一个错误吗?还是安全的东西?如果是的话,我该如何解决这个问题呢?

var x = 0;
addFile = function(addFileButton) {
    var form = document.getElementById('form');
    var box = document.createElement('input');
    box.type = 'file';
    box.name = 'photo[]';
    box.id = 'photo' + x;
    box.style.cssText = 'position:absolute; top:-200px;';
    box.onchange = function() {
        checkFileDup(this.value, x - 1);
    };
    form.appendChild(box);
    jQuery("#photo" + x).trigger('click');
    x++;
}
Run Code Online (Sandbox Code Playgroud)

ota*_*tay 5

这是IE的问题,通过javascript创建的输入[type = file]不能通过表单提交.

我的解决方案是在页面中创建一组隐藏的输入[type = file]元素,并在需要时使它们可见.