中文字幕日韩一区二区_国产一区二区av_国产毛片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这里只有精品视频 | 国产精品久久久久无码av | 久久久www成人免费无遮挡大片 | 99免费在线| av黄色在线 | 国产精品欧美一区二区三区不卡 | 四虎永久影院 | 黄色在线免费观看视频网站 | 国产一区二区三区免费视频 | 成人在线网 | 一区二区三区免费 | 欧美日本在线观看 | 精品一区二区三区在线观看国产 | 成人在线视频一区 | 2019天天操 | 久久神马 | 国产国产精品 | 亚洲视频观看 | 中文字幕在线一区二区三区 | 婷婷久| 一区二区三区视频免费观看 | 国产精品18hdxxxⅹ在线 | 日本黄色片免费在线观看 | 日韩中文字幕一区 | 久久av网站 | 天天玩天天操天天干 | 毛片一区二区三区 | 天天天天操| 欧美精品在线免费 | 国产精品久久久久久久一区二区 | 99热视 | 中文字幕在线看 | 色综合一区二区三区 | 久久精品视频一区二区三区 | 国产伦一区二区三区 | 亚洲 欧美 激情 另类 校园 | 久久精品中文 |