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

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

主站蜘蛛池模板: 久久好看视频 | 国内精品一区二区 | 思思玖玖 | 无遮挡毛片a级武则天 | 日本一区二区在线不卡 | 国产精品久久久久久久久ktv | 夜色福利院在线看青草一 | 日本高清中文字幕一区二区三区a | 男女一级做a爱过程免费视频 | 久久久久免费 | 91精品国产色综合久久不 | 欧美人体大胆私密视频 | 国产玖玖视频 | 亚洲成人视屏 | 色综合久久88色综合天天提莫 | 国产精品亚洲综合网站 | 加勒比精品久久一区二区三区 | 国产激情视频趣趣在线观看的 | 一级做a爰片欧美aaaa | 国产一区二区三区在线观看免费 | 国产精品久久久久久久成人午夜 | 中文字幕一区二区三区有限公司 | 91福利区| 色婷婷基地 | 天天色图 | 色呦呦在线播放 | 亚洲经典激情春色另类 | 91国内视频在线观看 | 欧美在线观看www | 玖玖玖视频在线观看视频6 玖玖免费 | 欧美成年黄网站色高清视频 | 好吊操视频这里只有精品 | 久9久9精品视频在线观看 | 久久久国产麻豆 | 人人干在线 | 综合涩 | 精品视频在线观看免费 | 国产成人资源 | 国内精品久久久久久久星辰影视 | 国产精品夜色一区二区三区 | 黄色大片网站在线观看 |