国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開(kāi)發(fā) > 正文

jQueryon()方法

2024-04-27 15:00:51
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

jQuery on()方法是官方推薦的綁定事件的一個(gè)方法。

$(selector).on(event,childSelector,data,function,map)

由此擴(kuò)展開(kāi)來(lái)的幾個(gè)以前常見(jiàn)的方法有.

bind()  $("p").bind("click",function(){    alert("The paragraph was clicked.");  });  $("p").on("click",function(){    alert("The paragraph was clicked.");  });delegate()  $("#div1").on("click","p",function(){    $(this).CSS("background-color","pink");  });
  $("#div2").delegate("p","click",function(){    $(this).css("background-color","pink");  });live()  $("#div1").on("click",function(){    $(this).css("background-color","pink");  });
  $("#div2").live("click",function(){    $(this).css("background-color","pink");  });

以上三種方法在jQuery1.8之后都不推薦使用,官方在1.9時(shí)已經(jīng)取消使用live()方法了,所以建議都使用on()方法。

t

多個(gè)事件綁定同一個(gè)函數(shù)

$(document).ready(function(){  $("p").on("mouSEOver mouseout",function(){    $("p").toggleClass("intro");  });});

多個(gè)事件綁定不同函數(shù)

$(document).ready(function(){  $("p").on({    mouseover:function(){$("body").css("background-color","lightgray");},      mouseout:function(){$("body").css("background-color","lightblue");},     click:function(){$("body").css("background-color","yellow");}    });});

綁定自定義事件

$(document).ready(function(){  $("p").on("myOwnEvent", function(event, showName){    $(this).text(showName + "! What a beautiful name!").show();  });  $("button").click(function(){    $("p").trigger("myOwnEvent",["Anja"]);  });});

傳遞數(shù)據(jù)到函數(shù)

function handlerName(event) {  alert(event.data.msg);}$(document).ready(function(){  $("p").on("click", {msg: "You just clicked me!"}, handlerName)});

適用于未創(chuàng)建的元素

$(document).ready(function(){  $("div").on("click","p",function(){    $(this).slideToggle();  });  $("button").click(function(){    $("<p>This is a new paragraph.</p>").insertAfter("button");  });});

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 都兰县| 玛曲县| 铜山县| 棋牌| 宣武区| 札达县| 明光市| 德惠市| 东乡县| 汝州市| 彭阳县| 板桥市| 永福县| 遂溪县| 襄垣县| 宁强县| 东兰县| 东阳市| 察隅县| 延川县| 连江县| 耿马| 汶川县| 长子县| 崇明县| 上饶县| 溧水县| 安新县| 桦甸市| 墨玉县| 江安县| 耒阳市| 郓城县| 木兰县| 什邡市| 合阳县| 隆化县| 广宗县| 清水河县| 临沭县| 通州市|