天天躁日日躁狠狠躁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久久在观看 | se01国产短视频在线观看 | 欧洲另类一二三四区 | 精品96在线观看影院 | 久久精品中文字幕免费 | 在线观看国产亚洲 | 999人在线精品播放视频 | 美娇妻的性奴史1一4 | 欧美影院在线观看完整版 mp4 | 人人啪日日观看在线 | 第一次玩老妇真实经历 | 男女啪啪抽搐呻吟高潮动态图 | 欧美日韩久久久精品A片 | 一本到高清视频在线观看三区 | 欧美国产精品主播一区 | 在线视频网站www色 在线视频免费国产成人 | 国产亚洲精品久久久久久国 | 無码一区中文字幕少妇熟女网站 | 棉签和冰块怎么弄出牛奶视频 | 恋夜秀场1234手机视频在线观看 | 秋霞三级理伦免费观看 | 超碰日韩人妻高清视频 | 久久影院午夜理论片无码 | 国内精品久久久久影院男同志 | 精品视频在线一区 | 广西美女色炮150p图 | 男男h啪肉np文总受 男男h开荤粗肉h文1v1 | 琪琪色原网站ying | 单亲妈妈3韩国电影免费观看 | 亚洲男人97色综合久久久 | 男女做爽爽爽视频免费软件 | 国产中文欧美日韩在线 | 中文字幕精品视频在线 | 国产在线精品亚洲观看不卡欧美 | 国产成人高清精品免费观看 | 99久久99 | 97夜夜澡人人爽人人模人人喊 |