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

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

主站蜘蛛池模板: 奇米网一区二区三区在线观看 | 亚洲黄色高清视频 | 中文字幕在线播放视频 | 国产福利视频第一导航 | 暖暖 视频 在线 观看 高清 | 久久99热这里只频精品6 | 天天射天天干天天插 | 欧美在线看欧美视频免费 | x69老师x日本 | 俺也去最新地址 | 亚洲综合免费视频 | 猫咪www958ii | 澳大利亚剧满足在线观看 | 亚洲福利天堂网福利在线观看 | 十分钟免费观看高清视频大全 | H厨房灌草莓 | 国产A级毛片久久久久久久 国产a级黄色毛片 | 国产乱国产乱老熟300部视频 | 99re这里只有精品视频 | 里番acg纲手的熟蜜姬训练场 | 久久综合给合久久狠狠狠… | 乡村教师电影版 | 丝袜情趣在线资源二区 | 大陆老太交xxxxxhd在线 | 国产AV综合手机在线观看 | 日本色女孩影院 | 肉奴隷 赤坂丽在线播放 | 国产中文字幕乱码一区 | 麻豆成人AV久久无码精品 | 闺蜜扒开我尿口使劲揉 | 精品国产5g影院天天爽 | 日韩精品一区二区三区色欲AV | 娇妻玩4P被三个男人伺候电影 | xart欧美一区在线播放 | 中文字幕乱码在线人视频 | 产传媒61国产免费 | 欧美性视频xxxxhd | 亚洲精品在线免费 | 亚洲 欧美 日本 国产 高清 | 成人公开免费视频 | old胖老太fat bbw青年 |