一。jQuery事件的分类:

1.鼠标事件:

代码:

 1 $(document).read(function(){
 2     //使用mouseover事件给导航栏改变背景颜色
 3    $(".nav-ul a").mouseover(function(){
 4        $(this).css(backgroundcolor="#f01e28");
 5    })
 6     //使用mouseout事件还原导航栏背景颜色
 7     $(".nav-ul a").mouseout(function(){
 8         $(this).css(backgroundcolor="#ff2832");
 9     })
10 
11 })

区别:

2.键盘事件:

代码:

 1 $(document).read(function(){
 2 
 3    $("[type=password]").keyup(function(){   //当释放键盘时
 4        $("#events").append("keydup");
 5    }).keydown(function(e){                //当按下键盘时
 6        $("#events").append("keydown");
 7    }).keypress(function(){               //向密码框输入字符时
 8        $("#events").append("keypress");
 9    });
10 
11     $(document).keydown(function(event){    
12         console.log(event);
13         if(event.keyCode==13){       //按回车时
14             alert("确认要提交?")
15         }
16     })
17 
18 })

3.浏览事件:

代码:

$(document).read(function(){

  $(window).resize(function(){
      console.log("浏览器被调整!")
  })

})

二。jQuery的绑定事件和移除事件

 

 

 代码:

 1 $(document).read(function(){
 2     //使用bind方法绑定一个事件
 3     $(".on").bind("mouseover",function(){
 4         $(".topDown").show();
 5     })
 6     //使用bind方法绑定多个事件
 7     $(".on").bind({
 8         mouseover: function () { 
 9             $(".topDown").show();
10         },
11         mouseout:function(){
12             $(".topDown").hide();
13         }
14     })
15 })

 

三。复合事件