jquery事件绑定

老版本用bind,新版本用on,off,

1.绑定一个事件:

  $("div").bind("click",function(){});

2.绑定多个事件:

  $("div").bind("click mouseover",function(){})

  或者:

    $("div").bind({

      'click':function(){}

    },{

      'mouseover':function(){}

    })

3.删除绑定事件:

   $("div").unbind();//删除全部绑定事件

  $("div").unbind("click");//删除某一个绑定事件

  像这种:

  $("div").bind("click",fn1);

  $("div").bind("click",fn2);

  function fn1(){};function fn1(){};

  删除某一个绑定事件:$("div").unbind("click",fn1);

4.时间委托

<script src="jquery/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#box").on("click",".button",function () {
                $(this).clone().appendTo("#box");
            })
        })
    </script>
</head>
<body>
<div id="box" style="position: absolute;top: 100px;left: 100px;background-color: red;">
    <input type="button" value="按钮" class="button">
</div>

原文地址:https://www.cnblogs.com/alex-xxc/p/10014815.html