简体   繁体   English

jQuery.submit() 未在 Firefox 中发送输入提交

[英]jQuery .submit() doesn't send input submit in Firefox

I have a little jQuery (1.6.2) script that changes the input submit value to "Sending..." and prevents it from working without a selected image.我有一个小 jQuery (1.6.2) 脚本,将输入提交值更改为“正在发送...”并防止它在没有选定图像的情况下工作。

$('form#upload').submit(function(event)
{
  event.preventDefault();

  var image = $('input[name="image"]');
  var upload = $('input[name="upload"]');

  if (image.val())
  {
    upload.val('Sending...');
    this.submit();
  }
});

image is an input file, upload is the input submit. image是输入文件, upload是输入提交。 It works fine in Chrome, but Firefox (5.0) does not send the input submit in the POST, only the image, which causes my server side script to fail.它在 Chrome 中运行良好,但 Firefox (5.0) 不会在 POST 中发送输入提交,只有图像,这会导致我的服务器端脚本失败。 I could work around that, but I'd like to know if I can fix that and I can't seem to find anything on it.我可以解决这个问题,但我想知道我是否可以解决这个问题,但我似乎找不到任何东西。

Simply remove the unconditional event.preventDefault();只需删除无条件event.preventDefault(); and only call it if the form should not be submitted.并且仅在不应提交表单时调用它。

$('form#upload').submit(function(event)
{

  var image = $('input[name="image"]');
  var upload = $('input[name="upload"]');

  if (image.val()) {
    upload.val('Sending...');
  }
  else {
    event.preventDefault();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM