更新时间:2023-02-16 22:28:09
根据 jQuery Events: Stop (Mis)Using Return False(存档链接),调用时返回false
执行三个任务:
According to jQuery Events: Stop (Mis)Using Return False (archived link), returning false
performs three tasks when called:
取消默认行为所需的唯一操作是preventDefault()
.发出 return false;
可以创建脆弱的代码.通常你只想要这个:
The only action needed to cancel the default behaviour is preventDefault()
. Issuing return false;
can create brittle code. Usually you'd want just this:
$("a").on( 'click', function (e) {
// e == our event data
e.preventDefault();
});
其次this"是javascript中的DOM元素,$(this)"是jQuery元素引用 DOM 元素.在 jQuery's this: demystified 阅读有关该主题的更多信息.
And secondly "this" is a DOM element in javascript and "$(this)" is a jQuery element that references the DOM element. Read more on the topic at jQuery's this: demystified.