on方法绑定事件后执行多次的处理方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>
<body>
      <button id="btn1">解绑</button>
      <button id="btn2">绑定</button>
      <button id="btn3">点击测试</button>
</body>
<script type="text/javascript" src="jquery-2.1.4.js"></script>
<script type="text/javascript" >
      $("#btn2").click(function(event) {
           $("#btn3").off("click");//绑定后进行解绑,就跟css动画进行后再前面加上stop()
            $("#btn3").on("click",demo);
            $("#btn1").click(function(event) {
                 $("#btn3").off("click")
            });
      });
      
      function demo(){
        alert()
      }
</script>
</html>

 

posted @ 2017-04-19 20:05  xuanPhoto  阅读(138)  评论(0)    收藏  举报