更新时间:2023-02-16 22:50:26
根据 jQuery事件:停止(误)使用返回假(存档链接),返回 false
调用时执行三个任务:
According to jQuery Events: Stop (Mis)Using Return False (archived link), returning false
performs three tasks when called:
取消所需的唯一操作默认行为是 preventDefault()
。发出返回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 element
引用DOM元素。请阅读 jQuery的内容:揭秘。
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.