1. 程式人生 > >jQuery on()方法給動態生成的元素繫結方法

jQuery on()方法給動態生成的元素繫結方法

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");   });