最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

return false;和e.preventDefault();的區(qū)別

 更新時間:2010年07月11日 12:29:38   作者:  
Have you ever seen those two things (in the title) being used in jQuery? Here is a simple
Have you ever seen those two things (in the title) being used in jQuery? Here is a simple example:
復(fù)制代碼 代碼如下:

$("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:
復(fù)制代碼 代碼如下:

$("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:
復(fù)制代碼 代碼如下:

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

測試代碼打包下載

相關(guān)文章

  • JS創(chuàng)建對象的六種方式

    JS創(chuàng)建對象的六種方式

    在js中,對象是鍵值對的集合,可以通過很多種方式創(chuàng)建; 本文給大家介紹了六種創(chuàng)建方式:對象字面量、構(gòu)造函數(shù)、Object.create()、工廠函數(shù)、class、單例模式,需要的朋友可以參考下
    2025-04-04
  • js的隱含參數(shù)(arguments,callee,caller)使用方法

    js的隱含參數(shù)(arguments,callee,caller)使用方法

    本篇文章只要是對js的隱含參數(shù)(arguments,callee,caller)使用方法進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • JavaScript仿聊天室聊天記錄

    JavaScript仿聊天室聊天記錄

    這篇文章主要為大家詳細介紹了JavaScript仿聊天室聊天記錄實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • JavaScript實現(xiàn)將UPC轉(zhuǎn)換成ISBN的方法

    JavaScript實現(xiàn)將UPC轉(zhuǎn)換成ISBN的方法

    這篇文章主要介紹了JavaScript實現(xiàn)將UPC轉(zhuǎn)換成ISBN的方法,涉及javascript字符串操作的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • JS之相等操作符詳解

    JS之相等操作符詳解

    下面小編就為大家?guī)硪黄狫S之相等操作符詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-09-09
  • 基于JS實現(xiàn)數(shù)字動態(tài)變化顯示效果附源碼

    基于JS實現(xiàn)數(shù)字動態(tài)變化顯示效果附源碼

    我們經(jīng)??吹揭壕щ娮颖順邮剑瑪?shù)字動態(tài)顯示,動態(tài)變化的在指定元素內(nèi)顯示數(shù)字。怎么實現(xiàn)效果呢?下面小編給大家?guī)砹嘶贘S實現(xiàn)數(shù)字動態(tài)變化顯示效果 ,感興趣的朋友一起看看吧
    2019-07-07
  • 菜單制作學(xué)習(xí)一個小東西

    菜單制作學(xué)習(xí)一個小東西

    菜單制作學(xué)習(xí)一個小東西...
    2006-09-09
  • js阻止事件追加的具體實現(xiàn)

    js阻止事件追加的具體實現(xiàn)

    可以使用 e.stopPropagation(); e.preventDefault();來阻止事件冒泡,和默認事件的執(zhí)行。但不能阻止事件的追加,如要追加,請看下面的實現(xiàn)方法
    2014-10-10
  • 利用location.hash實現(xiàn)跨域iframe自適應(yīng)

    利用location.hash實現(xiàn)跨域iframe自適應(yīng)

    其他一些類似js跨域操作問題也可以按這個思路去解決,需要的朋友可以測試下。
    2010-05-05
  • 使用JavaScript實現(xiàn)輪播圖效果完整實例

    使用JavaScript實現(xiàn)輪播圖效果完整實例

    我們在各種網(wǎng)頁中經(jīng)常見到輪播圖的效果,下面這篇文章主要給大家介紹了關(guān)于使用JavaScript實現(xiàn)輪播圖效果的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-01-01

最新評論

阜康市| 上高县| 得荣县| 太仆寺旗| 宁海县| 濮阳市| 永嘉县| 襄汾县| 格尔木市| 和政县| 道真| 宜黄县| 河北省| 剑河县| 南岸区| 嫩江县| 阿拉善右旗| 磐石市| 阆中市| 和政县| 静乐县| 蚌埠市| 类乌齐县| 咸宁市| 于都县| 西吉县| 冀州市| 浑源县| 牡丹江市| 丹江口市| 宝兴县| 华宁县| 汉中市| 井研县| 泽库县| 修文县| 子洲县| 拉孜县| 托里县| 泽普县| 吴忠市|