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

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

主站蜘蛛池模板: 亚洲中文字幕在线第六区 | 影音先锋男人资源813. | 亚洲精品免播放器在线观看 | 午夜精品国产自在现线拍 | 亚洲一在线 | 精品视频在线播放 | 99国内偷揿国产精品人妻 | 4虎影院午夜在线观看 | 一本道久在线综合道 | 成人在无码AV在线观看一 | 色宅男看片午夜大片免费看 | 国产亚洲欧美高清在线 | 日韩AV片无码一区二区三区不卡 | 啦啦啦WWW在线观看免费高清版 | 亚洲国产成人精品久久久久 | 美女诱惑性感揉胸 | 亚洲精品乱码久久久久久v 亚洲精品乱码电影在线观看 | jjzz动漫| 被爽到叫呻呤视频免费视频 | 亚洲人成电影网站在线观看 | 一本道无码字幕在线看 | 一区二区三区无码高清视频 | 国产精品99久久久久久WWW | 成人在线免费视频观看 | 性直播免费 | 天天狠狠弄夜夜狠狠躁·太爽了 | 久久久久久极精品久久久 | 欧美精品专区第1页 | 热九九99香蕉精品品 | 日韩精品一卡二卡三卡四卡2021 | 黄页网址大全免费观看 | 69日本人xxxx16—18 | 一本色道久久综合亚洲精品蜜桃冫 | 亚洲中文无码亚洲人在线观看- | 无码毛片内射白浆视频 | 娇女的呻吟亲女禁忌h16 | 女人被躁到高潮嗷嗷叫免费 | 日本不卡不码高清免费 | 黄色小说在线 | 日韩亚洲国产中文字幕欧美 | 我把寡妇日出水好爽 |