jquery的live转on的办法

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
 5 <script>
 6 $(document).ready(function(){
 7     setTimeout("$.appendText()",2000)
 8     $(document).on("mouseover mouseout","p",function(e){
 9         if(e.type=="mouseover")
10         {
11             $("body").css("background-color","lightgray");
12         }
13         else if(e.type=="mouseout")
14         {
15             $("body").css("background-color","lightblue");
16         }
17      });
18     $.appendText = function()
19     {
20     var txt1="<p style='border:1px solid red;'>Text.</p>";               // 以 HTML 创建新元素
21     var txt2=$("<p style='border:1px solid blue'></p>").text("Text.");   // 以 jQuery 创建新元素
22         var txt3=document.createElement("p");  // 以 DOM 创建新元素
23 txt3.innerHTML="Text.";
24     $("body").append(txt1,txt2,txt3);         // 追加新元素
25     }
26 });
27 </script></head><body><p>Click or move the mouse pointer over this paragraph.</p><input type='button' value='ssssssssssss' onclick='setTimeout()'>
28 </body>
29 </html>
View Code

最近从1.6.2升到1.9.1

发现live被取消了,只能用on  (die->off)

但是却发现为新增元素绑定事件的时候只能如上代码所示。

肯定很麻烦也很别扭,

不知道大家有没有什么更好的办法,请赐教

转载于:https://www.cnblogs.com/jasonlam/p/5401227.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值