jq的几种事件绑定

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="jquery-1.11.1.js"></script>
    <script>

        //这种绑定事件的方法是不会层叠的。
       $(document).click(function () {
           alert(1);
       });
       //第二种绑定:bind
       $(document).bind("click mouseenter", function () {
           alert(1);
       })
      //第三种
       $(document).delegate(".box","click mouseenter", function () {
           alert(1);
       })

        第四种(重点)
       $(document).on("click mouseenter",".box",{"name":111}, function (event) {
           alert(event.data.name);
       });

       $(document).on("click",".box", function () {
          alert(1);
       });
    </script>

</head>
<body>
<div class="box" style="width: 100px;height: 100px;background-color: pink;"></div>
</body>
</html>

 

posted @ 2018-01-05 10:17  松歌  阅读(163)  评论(0编辑  收藏  举报