码迷,mamicode.com
首页 > 其他好文 > 详细

on的用法

时间:2014-12-24 13:08:40      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <a class=‘alink‘ href=‘#‘>发送验证码</a>
</body>
</html>

css

a{ display:box; display:-webkit-box; box-pack:center; box-align:center; width:100px; height:100px; -webkit-box-pack:center; -webkit-box-align:center;}
.alink{ background-color:red;}
.disable{ background-color:grey;}

js

$(function(){
   $(document).on(‘click‘,‘a.disable‘,function(){  //只执行333,222不执行
      alert(333);
  });  
  $(‘a.alink‘).on(‘click‘,function(){
      $(this).addClass(‘disable‘);
  });
 
  $(‘a.disable‘).on(‘click‘,function(){  //对静态元素有效,但是绑定动态生成的a元素的事件时无效:
      alert(222);
  });

});

  

  http://jsbin.com/xowafesoxi/2/

  

on的用法

标签:

原文地址:http://www.cnblogs.com/positive/p/4182052.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!