一区二区久久-一区二区三区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();的區別,轉載需保留來源!

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

主站蜘蛛池模板: 中文字幕日韩精品一区口 | 黄色免费观看 | 69视频网| 色成年激情久久综合 | 国产精品国产午夜免费福利看 | 正在播放国产夫妻 | 伊人色综合网一区二区三区 | 色播亚洲精品网站 亚洲第一 | 国产欧美亚洲三区久在线观看 | 91久久亚洲最新一本 | 在线免费视频国产 | 欧美精品第56页在线视频观看 | 狠狠狠很橹影院 | 成人在线观看网址 | 色噜噜噜噜噜 | 全国最大色成免费网站 | 国产免费资源高清小视频在线观看 | 五月婷六月婷婷 | 福利在线观看视频 | 国产一区二区视频在线 | 六月丁香色婷婷 | 国产精品video | 91网站在线看 | 亚洲五月综合 | 一区二区三区网站 | 五月婷婷之婷婷 | 精品亚洲综合在线第一区 | 四虎4hu永久免费 | 亚洲一区二区三区在线网站 | 久久久久国产一级毛片高清片 | 欧美性一交激情视频在线 | 92精品国产自产在线观看48 | 激情五月视频 | 久热爱精品视频在线观看久爱 | 久久婷婷是五月综合色狠狠 | 欧美日本韩国一区二区 | 91精品福利 | 国内精品免费网站牛牛 | 国产在线啪 | 成年美女黄网站色大 | 国产亚洲精品九九久在线观看 |