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

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

主站蜘蛛池模板: 97午夜理伦影院在线观看 | 怡红院在线观看精品 | 人妇乱理三级 | dxj在线视频·男人的天堂网站 | 综合久久久久久久 | 日韩美女强理论片 | 国产精品久久久久免费视频 | 香蕉大久久 | 国产一进一出视频网站 | 91性视频| 亚洲精品美女久久久久网站 | 青草99 | 亚洲欧洲视频 | 美女很黄很黄的网站 | 亚洲一区二区三区久久精品 | 五月天激情社区 | 亚洲网站在线 | 亚洲伊人久久大香线蕉在观 | 国产精品亚洲综合一区在线观看 | 97高清国语自产拍中国大陆 | 131美女一区二区三区视频 | 天天干天天干天天天天天天爽 | 色呦呦网站| 精品视频在线观看视频免费视频 | 日韩加勒比 | 激情综合五月婷婷 | 成人97在线观看免费高清 | 视色4se视频在线观看 | 久久综合中文字幕 | 日本三级成人中文字幕乱码 | 久久久久久影院 | 男人把女人c爽的免费视频 男人操女人免费视频 | 99ri国产在线 | 色吧久久 | 久爱精品视频在线视频 | 色多多入口| 国产午夜视频在线观看网站 | 超清乱人伦中文视频在线 | 一区二区三区在线视频播放 | 2020国产精品自拍 | 久久久久这里只有精品 |