jQuery通过点击链接问题提交表单 [英] jQuery submit form by clicking link issue

查看:92
本文介绍了jQuery通过点击链接问题提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过点击链接来提交表单。我禁用了重定向,但出于某种原因.submit()不工作...
这是我试过的:
$ b

效果:重定向停止,没有表单提交,没有错误信息,卡在表单页面上:

  $('。jsubmit')。click(function e){
e.preventDefault();
$('form#fadmin')。submit();
});

效果:URL重定向,未提交表单,无错误消息
$点击(功能(e){
$('form#fadmin')。submit(); $ b $($。code $) b});

效果:重定向停止,没有表单提交,没有错误消息,停留在表单页面上:


$ b $ $ p $ $('。jsubmit')。click(function(e){
$('form#fadmin')。submit ();
返回false;
});

形式:

 < form action =method =postname =fadminclass =inputformid =fadmin> ...< / form> 

和其他一些组合包括trigger(),使用unbind()反转preventDefault()。我能够提交表单的唯一方法是触发点击提交按钮,但这不是真正的解决方案,因为我需要在多个页面上使用它,然后添加按钮然后隐藏它,这不是我想在每个页面上做...



我试图在Firefox和IE中运行它们,结果相同。



正在使用的其他一些JS,jQ代码是:默认引导程序和由ZendFramework2和ZFTables提供的响应。
任何帮助将不胜感激!



编辑:

表单中有以下提交按钮:

 < input id =mysubmittype =submitvalue =Register name =submit/> 

删除完这个之后,我的第一个例子非常完美。
奇怪,因为页面上没有其他表单或提交按钮,并且没有任何名称,ID,类型...

解决方案 div>

这个问题可能是你正在尝试在jQuery对象上调用submit(),而不是表单DOM元素。



请尝试以下代码作为第二行:

  $( '形式#fadmin')[0] .submit(); 


I'm trying to submit a form by clicking on a link. I disabled the redirection, but for some reason .submit() is not working... Here is what I have tried:

Effect: redirection stops, no form submission, no error message, stuck on the form page:

$('.jsubmit').click( function(e) {
    e.preventDefault();
    $('form#fadmin').submit();
});

Effect: URL redirection, form not submitted, no error message

$('.jsubmit').click( function(e) {
    $('form#fadmin').submit();
});

Effect: redirection stops, no form submission, no error message, stuck on form page:

$('.jsubmit').click( function(e) {
    $('form#fadmin').submit();
    return false;
});

The form:

<form action="" method="post" name="fadmin" class="inputform" id="fadmin">...</form>

And a bunch of other combination including trigger(), reversing the preventDefault() with unbind(). The only way I was able to submit the form was to trigger a click on the submit button but that is not really a solution in my case, because I need to use this on multiple pages and adding the button then hiding it is not something I would like to do on every page...

I have tried to run them in Firefox and IE with the same result.

Some other JS, jQ codes being used are: default bootstrap and respond provided by ZendFramework2 and ZFTables. Any help would be much appreciated!

EDIT:

The form had the following submit button:

<input id="mysubmit" type="submit" value="Register" name="submit" />

After removing this my first example above worked perfectly. Strange because there was no other forms or submit buttons on the page and nothing with the same name, id, type...

解决方案

The issue is probably that you are trying to call submit() on a jQuery object, not the form DOM element.

Try this as your second line of code:

$('form#fadmin')[0].submit();

这篇关于jQuery通过点击链接问题提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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