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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

jQueryjQueryon()方法

2019-11-14 14:41:02
字體:
供稿:網(wǎng)友

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

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

由此擴(kuò)展開來的幾個(gè)以前常見的方法有.

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)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 那曲县| 古浪县| 井研县| 星座| 广昌县| 达孜县| 莱西市| 长子县| 呼图壁县| 郴州市| 墨江| 永定县| 竹山县| 稻城县| 石首市| 磐安县| 周口市| 大悟县| 永丰县| 乐清市| 宜川县| 桂林市| 抚州市| 茂名市| 华亭县| 田阳县| 乃东县| 朝阳县| 鄄城县| 娄底市| 永新县| 河北区| 读书| 惠东县| 长海县| 屏东县| 黄梅县| 温宿县| 阿拉善盟| 菏泽市| 德清县|