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

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

Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:
復(fù)制代碼 代碼如下:
$("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:
復(fù)制代碼 代碼如下:
$("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:
復(fù)制代碼 代碼如下:
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技術(shù)return false;和e.preventDefault();的區(qū)別,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 伊人免费在线观看 | 婷婷激情综合 | 国产在线一区二区三区在线 | 美女图片在线视频精品播放 | 俺也去老色官网 | 99精品国产闺蜜国产在线闺蜜 | 欧美激情一区二区三区中文字幕 | 亚洲一二区视频 | 亚洲精品福利 | 国产在线拍揄自揄视精品不卡 | 五月天婷婷激情 | 成人久久精品 | 在线看的成人性视频 | 国产精品免费一区二区三区 | 美女胸又www又黄的网站视频 | 国产高清国产专区国产精品 | 国产区在线免费观看 | 野外一男一女一级毛片 | 国产精品免费观看视频播放 | 久草热在线观看 | 久中文字幕中文字幕亚洲无线 | 黄色avav| 婷婷综合五月中文字幕欧美 | 麻豆精品 | 麻豆国产精品免费视频 | 国产精品美女免费视频观看 | 午夜激情视频在线 | 亚洲一区二区中文字5566 | 久久精品爱国产免费久久 | 五月婷婷六月丁香综合 | 亚洲最黄视频 | 久久久久久麻豆 | 激情在线小说图片视频区 | 色综合自拍 | 国产区精品福利在线观看精品 | 女人的天堂网 | 91在线永久| 五月婷亚洲 | 一级毛片成人午夜 | 韩国福利影视一区二区三区 | 色com|