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

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

主站蜘蛛池模板: 十八禁久久成人一区二区 | 91久久综合精品国产丝袜长腿 | 日韩av片无码一区二区不卡电影 | YELLOW日本免费观看播放 | 色婷婷五月综合中文字幕 | 天堂在线亚洲精品专区 | 99久久精品毛片免费播放 | 色噜噜狠狠一区二区三区 | 成 人 免费 黄 色 网站无毒下载 | 台湾佬休闲中性娱乐网 | 无套内射纹身女视频 | 国产69精品久久久久乱码免费 | 国产精品亚洲欧美一区麻豆 | 国产美女视频一区二区二三区 | 久久性生大片免费观看性 | 欧美久久综合性欧美 | 干丝袜美女| 国产精品VIDEOSSEX久久发布 | 2018高清国产一区二区三区 | 娇小萝被两个黑人用半米长 | 十八禁肉动漫无修在线播放 | 国产精品嫩草影院一区二区三区 | 久久久这里有精品999 | 国产无遮挡色视频免费观看性色 | 美丽的姑娘BD在线观看 | 俄罗斯12x13x处 | 色宅男看片午夜大片免费看 | 99久久精品免费精品国产 | 亚洲人成77777 | 六六影院午夜伦理 | 国产成人精品免费视频下载 | 天堂精品国产自在自线 | 激情内射亚洲一区二区三区爱妻 | 精品蜜臀AV在线天堂 | 人妖xxhdxx | 亚洲美女视频高清在线看 | 欧美激情视频在线观看一区二区三区 | 99热这里只有的精品 | 成人动漫百度影音 | 毛片在线播放网址 | 国产精品永久AV无码视频 |