调用DOM提交方法时jQuery提交事件不会被触发 [英] jQuery submit event not fired when calling DOM submit method

查看:114
本文介绍了调用DOM提交方法时jQuery提交事件不会被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 DOM表单提交方式提交表单, jQuery提交事件处理程序未被调用,即使w3c说:它执行与提交按钮相同的操作。

When I use the DOM form submit method to submit a form, the jQuery submit event handler isn't called, even though w3c says: "It performs the same action as a submit button."

我尝试使用jQuery 1.11.0和2.1.0。

I tried with jQuery 1.11.0 and 2.1.0.

<form id="form">
    <button type="button" onclick="document.getElementById('form').submit()">submit onClick</button>
</form>

请参阅 http://jsfiddle.net/g0kxmdmw/6/ 获取完整示例。

在Firefox和Chrome中,按Enter键文本输入,点击提交按钮和提交jquery将触发处理程序并取消表单提交,而提交 onClick 和提交js dom t触发处理程序,并执行提交(一个 GET 请求)。

In both Firefox and Chrome, pressing enter in the text input, clicking "submit button" and "submit jquery" will all trigger the handler and cancel the form submit, while "submit onClick" and "submit js dom" don't trigger the handler, and will perform the submit (a GET request).

我预计调用提交方法将显示与点击提交按钮相同的行为,但不会。这是jQuery中的错误吗?

I expected that calling the submit method would show the same behaviour as clicking a submit button, but it doesn't. Is this a bug in jQuery?

推荐答案

不,调用form的submit()方法不会触发submit事件,所以没有事件处理程序将被触发。

No, calling the form's submit() method does not trigger the submit event so none of the event handlers will get triggered.

只有当用户通过按钮点击或任何此类操作触发提交事件时,才会触发提交事件。

The submit event will be fired only when the user triggers it via a button click or any such actions.

提交活动


调用此方法时,不会触发表单的onsubmit事件处理程序(例如onsubmit =return
false;)从
基于Gecko的应用程序。一般来说,不能保证由HTML用户代理调用

The form's onsubmit event handler (for example, onsubmit="return false;") will not be triggered when invoking this method from Gecko-based applications. In general, it is not guaranteed to be invoked by HTML user agents.

这篇关于调用DOM提交方法时jQuery提交事件不会被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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