一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

return false;和e.preventDefault();的區別

Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:
復制代碼 代碼如下:
$("a").click(function() {
$("body").append($(this).attr("href"));
return false;
}

That code would append the href attribute as text to the body every time a link was clicked but not actually go to that link. The return false; part of that code prevents the browser from performing the default action for that link. That exact thing could be written like this:
復制代碼 代碼如下:
$("a").click(function(e) {
$("body").append($(this).attr("href"));
e.preventDefault();
}

So what's the difference?


The difference is that return false; takes things a bit further in that it also prevents that event from propagating (or “bubbling up”) the DOM. The you-may-not-know-this bit is that whenever an event happens on an element, that event is triggered on every single parent element as well. So let's say you have a box inside a box. Both boxes have click events on them. Click on the inner box, a click will trigger on the outer box too, unless you prevent propagation. Like this:

演示地址:http://css-tricks.com/examples/ReturnFalse/
So in other words:
復制代碼 代碼如下:
function() {
return false;
}

// IS EQUAL TO

function(e) {
e.preventDefault();
e.stopPropagation();
}

It's all probably a lot more complicated than this and articles like this probably explain it all a lot better.


參考:

1.The difference between ‘return false;' and ‘e.preventDefault();'
2.Event order

測試代碼打包下載

JavaScript技術return false;和e.preventDefault();的區別,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 怡红院视频网 | 美女张腿男人桶免费视频 | 成人午夜视频在线 | 午夜视频一区二区 | 午夜免费视频网站 | 2021在线永久免费视频 | 亚洲射图 | 岛国a视频 | 四虎影在线永久免费观看 | 久久久香蕉 | www.欧美.com| 香港aa三级久久三级 | 中文字幕在线视频在线看 | 激情图片激情小说激情视频 | 丁香四月婷婷 | 国产 麻豆 欧美亚洲综合久久 | a级精品国产片在线观看 | 亚洲成a人一区二区三区 | 中文字幕乱码二三区免费 | 欧美视频一 | 中文字幕激情视频 | 精品色哟哟视频在线观看 | 国产精品区免费视频 | 天干天干夜天干天天爽 | 黄色免费网站在线观看 | 日韩中文字幕在线有码视频网 | 一区二区视频网 | 美女一区二区在线观看 | 日韩a毛片 | 九月婷婷综合 | 国内精品美女久久久久 | 精品国产免费一区二区 | 春色视频一区二区三区 | 亚洲一区在线播放 | 中文字幕午夜乱理片 | 91精品视频网站 | 久久伊人成人网 | 四虎最新永久免费视频 | 色老板在线视频 | 91精品福利观看 | 国产精品亚洲片夜色在线 |