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

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

主站蜘蛛池模板: 欧美.成人.综合在线 | 思思久久99热免费精品6 | 亚洲玖玖 | 五月天激情开心网 | 亚洲欧美成人永久第一网站 | 成人在线视频国产 | 美女三级毛片 | 国产剧情一区二区 | 国产精品久久亚洲一区二区 | 日本高清在线精品一区二区三区 | 成人小视频在线播放 | 亚洲国产一区在线 | 夜夜未满十八勿进的爽爽影院 | 四虎永久免费网站免费观看 | 伊人久久五月天 | 日本人乱人乱亲乱色视频观看 | 久草免费在线色站 | 91大神精品长腿在线观看网站 | 91网视频在线观看 | aaa黄色片| 亚洲小说欧美激情另类 | 亚洲最黄视频 | 中文字幕区 | 91成人在线视频 | 九色国产在视频线精品视频 | 久久99精品久久久久子伦 | 中文国产成人精品久久水 | 国产高清精品一级毛片 | 色婷婷综合和线在线 | 国内精品久久久久久不卡影院 | 美女又胸大又黄的网站 | 影音先锋中文一区亚洲 | 精品国产免费一区二区三区 | 日韩色视频一区二区三区亚洲 | 岛国一区 | 亚洲欧美视频在线播放 | 久久国产精品视频一区 | 国产精品v欧美精品v日韩 | 大尺度福利视频 | 真实国产乱子伦精品免费 | 华人亚洲欧美精品国产 |