e.preventDefault()的位置很重要 [英] does location of e.preventDefault() matter

查看:158
本文介绍了e.preventDefault()的位置很重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的jquery函数中使用 preventDefault()来阻止提交按钮提交正常方式。 的位置preventDefault()是否重要。它必须先来或者可以是函数中的最后一件事吗?

I use preventDefault() in my jquery functions to prevent submit buttons from submitting the normal way. Does the location of preventDefault() matter. Does it have to come first or can be last thing in the function?

推荐答案

不,这没关系:
https://developer.mozilla.org/en-US / docs / Web / API / Event / preventDefault

这与返回 false 不同,因为当你返回时,函数中的其他所有内容都将被放弃。

This is different from returning false, since when you returns, everything else in the function are abandoned.

如上面给出的MDC链接中所述:

As said in the MDC link given above:


在任何
阶段的事件流程中调用 preventDefault 取消事件,
表示任何默认操作
通常由实施
执行的事件将不会发生

Calling preventDefault during any stage of event flow cancels the event, meaning that any default action normally taken by the implementation as a result of the event will not occur.

这篇关于e.preventDefault()的位置很重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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