e.preventDefault()的位置很重要 [英] does location of e.preventDefault() matter
问题描述
我在我的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屋!