jQuery鼠标移出移入、键盘事件

187 阅读1分钟
     【鼠标移入和移出】
     hover 由mouseenter和mouseleave组成 
     $('.div1').hover(function(){
         console.log(1);
     })
     
      mouseenter mouseleave ★在进入子元素区域的时候不会触发
     $('.div1').mouseenter(function(){
         console.log('mouseenter');
     })
     $('.div1').mouseleave(function(){
         console.log('mouseleave');
     })

      mouseover和 mouseout 在进入子元素区域的时候也会触发
     $('.div1').mouseover(function(){
        console.log('mouseover')
     })
     $('.div1').mouseout(function(){
         console.log('mouseout')
     })
     
     
     【键盘事件】
     按下键盘时 
     $('input[type=text]').keydown(function(){
         alert('我按下了')
     })
     释放按键时 
     $('input[type=password]').keyup(function(){
         alert('鼠标抬起了')
     })
     产生可打印的字符时 连续敲击键盘的时候触发 
     $('input[type=password]').keypress(function(){
         alert('连续敲击键盘')
     })