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

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

主站蜘蛛池模板: 黑人美国一级一级爰片 | 天天做天天爱天天爽天天综合 | 国产麻豆自拍 | 国产精品日韩欧美一区二区三区 | 激情综合丁香 | 六月激情综合 | 91社区在线观看精品 | 欧美综合视频 | 精品国产一区二区三区麻豆小说 | 无码一区二区三区视频 | 日韩精品第二页 | 久久亚洲网站 | 国产区更新 | 在线免费看污视频 | 亚洲乱亚洲乱妇41p国产成人 | 国产一级毛片午夜福 | 国产区二区 | 国产一区二区在免费观看 | 91人前露出精品国产 | 国产成人精品一区二区仙踪林 | 91婷婷| 色偷偷7777www人 | 亚洲视频第一页 | 在线播放91 | g0g0亚洲大胆肉体艺术 | 亚洲区在线 | 欧美综合网站 | 国语对白精品视频在线观看 | 国产极品美女在线 | 91福利片| 欧美在线视频网站 | 被公侵犯肉体中文字幕一区二区 | 国产成人亚洲综合 | 大杳蕉伊人狼人久久一本线 | 夜夜操影院 | 日本妇人成熟免费不卡片 | 四虎影视久久久 | 免费国产97久久青草 | 国产成人精品免费2021 | 国产麻豆久久 | 日本妇人成熟免费不卡片 |