on的用法

<!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; 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/

  

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