jQuery的on方法和bind绑定多个事件

on方法是官方推荐使用的方法比较新

1. on:

多个事件绑定同一个函数

$(document).ready(function(){

  $("p").on("mouseover mouseout",function(){

    $("p").toggleClass("intro");

  });

});

多个事件绑定不同函数

$(document).ready(function(){

  $("p").on({

    mouseover:function(){$("body").css("background-color","lightgray");},  

    mouseout:function(){$("body").css("background-color","lightblue");}, 

    click:function(){$("body").css("background-color","yellow");}  

  });

});

2. bind:

$("#registerBtn").bind("click dblclick", function(){
            location.href = "register.html";
        });

posted @ 2015-07-07 17:22  周建旭  阅读(2579)  评论(0编辑  收藏  举报