【问题标题】:jquery .submit + requesting the same file again [duplicate]jquery .submit +再次请求相同的文件[重复]
【发布时间】:2012-09-11 06:59:09
【问题描述】:

可能重复:
Upload files using input type=“file” field with .change() event not always firing in IE and Chrome

我有以下代码使用 .submit() 成功上传图片

// Photo Upload Form - AutoUpload
$('input#file').change(function() {
    var maxsize = '20971520';
    var fileExtension = $(this)
                            .val()
                            .split('.')
                            .pop()
                            .toLowerCase();

    if(this.files[0].size > maxsize) {
        $('h4#maxFileSizeExceeded').show();

    }else if($.inArray(fileExtension, ['gif','png','jpg','jpeg']) == -1) {
        $('h4#fileTypeNotAllowed').show();

    }else{
        if(pushState == '0') {
            $('div#uploadPercentage').hide();
            $('img#uploadGifLoaderHTML4').fadeIn('fast');
        }
        $('form#joinPhotoUploadForm').submit();
        jcrop_api.destroy();

        $('div#croppingBackgroundContainer').fadeIn(1000);
        $('div#cropBoxWrapper').css('margin-left', '0px');
    }
});

我遇到的问题是,如果用户再次请求相同的文件,则没有更改并且提交不会触发。

有没有办法再次请求同一个文件,或者再次知道它的同一个文件,或者可以对输入 type="file" 进行某种重置?

*********************更新

      <form action="scripts/php/photo_processing.php?page=join&section=precrop" id="joinPhotoUploadForm" enctype="multipart/form-data">
        <input type="file" name="file" id="file"><br>
      </form>

用户单击浏览按钮并可以选择图像。如果用户选择不同的图像,图像将上传。但是,如果用户选择相同的图像,.change() 函数根本不会触发。我假设是因为它保持与以前相同的状态。

谢谢

【问题讨论】:

  • The user requests the same file again。用户如何请求它?只是作为浏览中的图像?它会加载到页面中吗?将显示图像的脚本发布给用户会有很大帮助,因为问题可能就在那里。
  • 我猜你应该在成功提交回调时清除文件上传控件的内容。它应该可以工作。
  • 如何清除文件上传控件的内容?

标签: jquery html


【解决方案1】:

如果在input[type=file] 中选择了相同的文件,则不会调用change 事件,因为没有更改。添加一个按钮以再次触发您的代码或使用表单上的submit 事件。

【讨论】:

  • 我不想要另一个按钮 - 只需选择一个按钮,它就会从那里触发。有没有办法在提交后重置 input[type=file] 以便 .change() 再次工作?
  • 更重要的是,您的问题 herehere 有重复。
猜你喜欢
  • 2014-10-20
  • 2011-10-09
  • 2023-04-04
  • 2016-08-21
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多