本文介绍了如果使用.remove(),表单将不会提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Firefox,jQuery或者两者都有点麻烦。 OS是Windows 7,Firefox是版本4.0.1,jQuery介于1.5到1.6之间。基本上我有一个带有按钮的窗体

code>元素,通过jQuery附加一个click事件,删除按钮最接近的父元素 div 。这一切都很好。



现在问题出现在您执行上述操作后尝试提交表单。 Chrome,IE,Opera和Safari提交表单。另一方面,Firefox拒绝提交表单。

我甚至试过 $(form)。

在Firebug中无效。 >这是对jsFiddle的测试,只需点击 - 按钮,然后在Firefox中点击 submit 看看我的意思。



对此事的任何帮助都非常感谢!

编辑:我需要能够通过附加到表单元素外的按钮的Javascript / jQuery事件来提交表单。我花了最后几天挣扎着这个奇怪的行为,终于来到这个线程和 IE)。

这个问题似乎与我们在处理提交事件时删除节点并因此中断了提交事件的事实有关。 。

因此,在button元素中添加type =button实际上可以解决这个问题。




I'm having a spot of bother with either Firefox, jQuery or both. OS is Windows 7, Firefox is version 4.0.1 and jQuery is between 1.5 - 1.6.

Basically I have a form with a button element within, to which a click event is attached via jQuery which removes the button's closest parent div. This all works wonderfully.

Now the problem comes when you try to submit the form after carrying out the aforementioned action. Chrome, IE, Opera and Safari submit the form fine. Firefox on the other hand refuses to submit the form at all.

I've even tried $("form").submit(); in Firebug to no avail.

Here is a test on jsFiddle, simply click the - button and then submit in Firefox to see what I mean.

Any help on the matter is much appreciated!

Edit: I need to be able to submit the form via a Javascript/jQuery event attached to a button outside of the form element.

解决方案

I think I've got the final solution for this problem.I've spend the last couple of days struggling with this strange behavior and finally came accross this thread and this one which helped me a lot.. =))

The button element has a 'type' attribute which is set by default to 'submit' in almost all browsers (except IE).

The problem seems to be related to the fact that we're removing the node while processing the submit event and therefore breaking the submit event of the form...

So adding type="button" to the button element will actually solve this issue.

Here is a workign jsFiddle example.

这篇关于如果使用.remove(),表单将不会提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:27