jQuery .submit()+禁用输入文件 [英] jquery .submit() + disable input file

查看:61
本文介绍了jQuery .submit()+禁用输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种使用.change()和.submit()的形式,只要用户选择了一张就可以上传照片.我现在正在尝试在commit()开始后在输入文件上实现禁用功能,以避免同时进行多次上载.

I have a form that is using .change() and .submit() to upload a photo as soon as a user selects one. I'm now trying to implement a disabled on the input file after the submit() has started to avoid multiple uploads at the same time.

HTML:

  <form action="includes/photos.php" id="joinPhotoUploadForm" enctype="multipart/form-data">
    <input type="file" name="file" id="file"><br>
  </form>

JQUERY:

$('input#file').change(function() {
    $('form#joinPhotoUploadForm').submit();
    $('input#file').prop('disabled', true);     // Prevent Multiple Files Uploads
  }
});

捕获位于IE下,只有.#submit()在第二次上传开始时才禁用输入#文件.

The catch is under IE only the input#file is disabled before the .submit() starts on the second upload onwards.

在.submit()启动之前,是否有一种方法可以防止残疾人发生?

Is there a way to prevent the disabled from occuring until the .submit() has started?

还有另一种方法可以实现这一目标吗?还有其他我可以禁用的功能吗?我可以解除绑定.change()吗?注意:稍后(在ajax成功返回之后)启用禁用.

Is there another way to achieve this? something else I could disable? Could I unbind the .change()? Note: the disable is enabled later (after ajax return successfully).

谢谢

推荐答案

如果文件输入被禁用,则需要阻止表单再次提交.第二个eventListener将为您做到这一点.

You need to prevent the form from submitting again if the file input is disabled. the second eventListener will do that for you.

$('input#file').change(function() {
    $('form#joinPhotoUploadForm').submit();
    $('input#file').prop('disabled', true);     // Disable to Prevent Multiple Files Uploads
});

$("#joinPhotoUploadForm").submit(function(e) {
  if ($(this).find("#file").is(":disabled")) {
    e.preventDefault();
  }
});

这篇关于jQuery .submit()+禁用输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆