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

return false;和e.preventDefault();的區(qū)別

Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:
復(fù)制代碼 代碼如下:
$("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:
復(fù)制代碼 代碼如下:
$("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:
復(fù)制代碼 代碼如下:
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技術(shù)return false;和e.preventDefault();的區(qū)別,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 国产在线精品亚洲另类 | 99热婷婷国产精品综合 | 日本高清免费一本在线观看 | 好湿好滑好硬好爽好深视频 | 国产色情短视频在线网站 | 99 久久99久久精品免观看 | 久久精品国产亚洲AV久五月天 | 人体内射精一区二区三区 | a级精品九九九大片免费看 A级韩国乱理伦片在线观看 | 国产嫩草影院精品免费网址 | 国产一区二区三区四区五在线观看 | 久久精品视频91 | 国产乱国产乱老熟300部视频 | 久久亚洲人成国产精品 | bbw极度另类孕妇 | 狠狠色噜噜狠狠狠狠米奇777 | 伊人久久大香线蕉综合色啪 | 欧美内射AAAAAAXXXXX | 日韩 亚洲 欧美 中文 高清 | 暖暖 免费 高清 日本 在线 | 高清欧美性猛交xxxx黑人猛交 | 秘密教学93话恩爱久等了免费 | 99精品国产免费观看视频 | 自拍黄色片 | 99国产精品久久 | 69日本xxⅹxxxxx18 | 国产在线精品亚洲二品区 | 综合亚洲桃色第一影院 | 91福利国产在线观看网站 | 久久99精品AV99果冻 | 爱暖暖1000部免费 | 97欧美精品大香伊蕉在人线 | 精品一区二区三区免费观看 | 麻花豆传媒剧国产免费mv观看 | 久久久久久久伊人电影 | 好妞操| 亚洲第一成年人网站 | 中文字幕高清在线观看 | 97视频在线观看视频最新 | 富婆找黑人老外泻火在线播放 | 亚洲第一综合天堂另类专 |