abstract:語法:$(document).ready(function(){ }) 不能和<body onload="">一起使用focus()當元素獲得焦點change()當元素的值發(fā)生改變的時候click()點擊事件dblclick()雙擊事件mouseover() 當鼠標指針位于元素上方時會發(fā)生mouseover事件mouseenter() 當鼠標指
語法:
$(document).ready(function(){
})
不能和<body onload="">一起使用
focus()當元素獲得焦點
change()當元素的值發(fā)生改變的時候
click()點擊事件
dblclick()雙擊事件
mouseover() 當鼠標指針位于元素上方時會發(fā)生mouseover事件
mouseenter() 當鼠標指針穿過元素時會發(fā)生mouseenter事件
mousemove() 當鼠標指針在指定的元素中移動時,就會發(fā)生該事件
mouseleave() 當鼠標指針離開元素時
mouseout() 當鼠標指針從元素上移開時
mousedown() 當鼠標指針移動到元素上方并按下鼠標按鍵時
mouseup() 當在元素上松開鼠標按鍵時
resize() 當調整當前瀏覽器窗口大小時
pageX() 屬性是鼠標指針的位置,相對于文檔的左邊緣 event.pageX event:必須 參數(shù)來自事件綁定函數(shù)
pageY() 屬性是鼠標指針的位置,相對于文檔的上邊緣 event.pageY event: 必須 參數(shù)來自事件綁定函數(shù)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery事件方法</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ /*$('input').blur(function(){ $('input').css('background','red') }) $('input').focus(function(){ $('input').css('background','blue') })*/ /*$('input').change(function(){ $('input').css('background','pink') }) $('button').click(function(){ $('div').css('backgroundColor','blue') })*/ /*$('button').dblclick(function(){ $('div').css('backgroundColor','blue') })*/ /*$(document).mousemove(function(a){ $('span').text('x:'+a.pageX+'y:'+a.pageY) }) n=0; $(window).resize(function(){ $('b').text(n++) })*/ /*$('div').mouseenter(function(){ $('div').css('backgroundColor','pink') }) $('div').mouseleave(function(){ $('div').css('backgroundColor','blue') })*/ /*$('div').mouseout(function(){ $('div').css('backgroundColor','blue') })*/ /*$('div').mouseover(function(){ $('div').text('大家好,我是星辰') })*/ $('div').mousedown(function(){ $('div').text('按下') }) $('div').mouseup(function(){ $('div').text('松開') }) }) </script> <!-- <input type="text" name=""> <div style="width:100px;height:100px;background-color:red;margin-top: 20px;"></div> <button>點擊</button> --> <!-- 鼠標位置:<span></span> 窗口大小被調整的次數(shù):<b></b> --> <div style="width:100px;height: 100px;margin:50px auto;background: red;"></div> </body> </html>