IE9上的Jquery表单插件问题

Jquery form plug in issue on IE9

本文关键字:插件 问题 表单 Jquery 上的 IE9      更新时间:2023-09-26

我正在使用JQuery Form插件。在IE9中,有时我会在控制台上收到"SCRIPT5:拒绝访问"错误。它适用于Mozilla和Chrome。这是我的代码:

表单:在我看来,这是一个隐藏的表单,我是在文件类型输入控件的onchange事件上提交这个表单的。

<form id="fileAttachment" action="@Url.Action("AttachFile", "Attachment")" method="post" enctype="multipart/form-data">
    <input type="file" id="upload" name="upload" onChange="submitFormOnFileSelection()"/>
    <input type="submit" id="xxx" name="asd" />
</form>

提交表单的代码:

 $(document).ready(function () {
        var options = {
            beforeSend: function () {
            },
            uploadProgress: function (event, position, total, percentComplete) {
            },
            success: function () {
            },
            complete: function(response) {
                $("#AttachmentArea").html(response.responseText);
            },
            error: function () {
                $("#AttachmentArea").html("<font color='red'> ERROR: unable to upload files</font>");
            }
        };
        $("#fileAttachment").ajaxForm(options);
    });
function submitFormOnFileSelection() {
        if ($("#upload").val() != '') {
            $('#fileAttachment').submit(function() {
                $("#fileAttachment").ajaxSubmit(options);
            });
            $("#upload").val('');
        }
    }

IE9出现问题??

谢谢你的帮助。

您不能在ie中对文件输入执行$("#upload").val('')操作。清除它的正确方法是用新输入替换输入。

$("#upload").replaceWith('<input type="file" id="upload" name="upload" onChange="submitFormOnFileSelection()"/>');