jQuery .submit()不会在Firefox中发送输入提交 [英] jQuery .submit() doesn't send input submit in Firefox

查看:133
本文介绍了jQuery .submit()不会在Firefox中发送输入提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的jQuery(1.6.2)脚本,将输入提交值更改为正在发送...,并防止它在没有选定图像的情况下运行。



<提交(功能(事件)
{
event.preventDefault();

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

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

image 是一个输入文件, upload 是输入提交。它在Chrome中工作正常,但Firefox(5.0)不会在POST中发送输入提交,只会发送图像,导致我的服务器端脚本失败。我可以解决这个问题,但我想知道我是否可以解决这个问题,而且我似乎无法找到任何东西。

解决方案

div>

只要删除无条件的 event.preventDefault(); ,只有在 >

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

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

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


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.

$('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. 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. 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(); 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();
  }
});

这篇关于jQuery .submit()不会在Firefox中发送输入提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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