天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

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

主站蜘蛛池模板: 日本艳妓BBW高潮一19 | 色偷偷91综合久久噜噜 | xxnxx美女| 国产精品久久久久久免费字体 | 天堂tv免费tv在线tv香蕉 | 欧美特级另类xxx | 国产亚洲精品久久77777 | 中文字幕va一区二区三区 | www.狠狠色 | 久久视热频国只有精品 | 忘忧草在线影院WWW日本动漫 | 国产精品内射久久久久欢欢 | 亚洲天堂视频网站 | 国产精品99久久久久久AV色戒 | 中文天堂www资源 | 网红刘婷hd国产高清 | 亚洲日韩天堂在线中文字幕 | 污漫日本E同人 | 日韩高清在线亚洲专区 | 99久酒店在线精品2019 | 欧美久久综合性欧美 | 东热rq大乱交 | 国产午夜婷婷精品无码A片 国产午夜视频在永久在线观看 | 大胆国模一区二区三区伊人 | 色人格影院第四色 | www.97干 | 最新果冻传媒在线观看免费版 | 国内精品免费久久影院 | 欧美精品乱码99久久蜜桃 | 制服国产欧美亚洲日韩 | 亚洲精品一线二线三线无人区 | 亚州综合网 | 国产精品视频在线自在线 | 成年人免费在线视频观看 | 99久久爱re热6在线播放 | 国产无遮挡色视频免费观看性色 | 国产又粗又猛又爽又黄的免费视频 | 麻豆产精品一二三产区区 | 国产高清在线a视频大全 | www.97干 | 午夜人妻理论片天堂影院 |