中文字幕日韩一区二区_国产一区二区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();的區別,轉載需保留來源!

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

主站蜘蛛池模板: 在线欧美小视频 | 免费av在线| 日韩在线h | 青青操91 | 精品久 | av网址在线播放 | 国产成人精品999在线观看 | 日韩伦理一区二区 | 中文字幕高清av | 精品亚洲一区二区三区 | 久久久久久久99 | 国内精品免费久久久久软件老师 | 美女天天操 | 日韩中文字幕在线 | 操操日| 激情五月婷婷在线 | 欧美综合一区 | 国产成人精品免高潮在线观看 | 日本久久综合网 | 在线欧美视频 | 亚洲一区二区三区观看 | 欧美日韩在线一区二区三区 | www.v888av.com | 一区二区在线看 | 国产成人av一区二区三区 | 91精品国产综合久久久久久首页 | 久久综合狠狠综合久久 | 97精品国产97久久久久久免费 | 天天射天天干 | 性高湖久久久久久久久 | 狠狠的日 | 欧美日韩电影一区 | 男女羞羞视频在线免费观看 | 日韩久久久久久久久久久 | 日韩精品一区二区三区免费观看 | 亚洲在线电影 | 一区二区三区欧美在线观看 | 91成人精品 | 在线观看亚洲专区 | 伊大人久久 | 一区二区三区在线 |