摘要:依舊上圖 粘代碼提交沒反應(yīng)<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JQ事件函數(shù)</title> <script type="text/javascript" sr
依舊上圖 粘代碼提交沒反應(yīng)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JQ事件函數(shù)</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> </head> <body> <script type="text/javascript"> // 在Jquery中是以調(diào)用事件函數(shù)的形式來觸發(fā)事件的,如js中的onclick事件,在JQuery中則用click()來替代簡(jiǎn)單的理解:事件方法會(huì)觸發(fā)匹配元素的事件,或者將函數(shù)綁定到所有匹配元素的某個(gè)事件 // ready()當(dāng)我們的dom已經(jīng)加載,頁面已經(jīng)加載完,觸發(fā)的事件==js的onload // 語法:$(document).ready(function(){ // }) // *不能與<body onload="">一起使用 // blur()當(dāng)元素失去焦點(diǎn) == onblur() // focus()當(dāng)元素獲得焦點(diǎn) ==onfocus // change()當(dāng)元素的值發(fā)生改變的時(shí)候 // dblclick()雙擊事件 // mouseover() 當(dāng)鼠標(biāo)指針位于元素上方時(shí)會(huì)發(fā)生mouseover事件 // mouseenter() 當(dāng)鼠標(biāo)穿過元素時(shí)會(huì)發(fā)生mouseenter事件 // mousemove() 當(dāng)鼠標(biāo)在指定的元素中移動(dòng)時(shí),就會(huì)發(fā)生該事件 // mouseleave()當(dāng)鼠標(biāo)指針離開元素時(shí) // mouseout() 當(dāng)鼠標(biāo)指針從元素上移開時(shí) // mouseup() 當(dāng)在元素上松開鼠標(biāo)按鍵時(shí) // resize() 當(dāng)調(diào)整當(dāng)前瀏覽器窗口大小時(shí) // pageX 屬性是鼠標(biāo)指針的位置,相對(duì)于文檔左邊緣 event.pageX event:必須 參數(shù)來自事件綁定函數(shù) //pageY 屬性是鼠標(biāo)指針的位置,相對(duì)于文檔上邊緣 event.pageX event:必須 參數(shù)來自事件綁定函數(shù) $(document).ready(function(){ // $('input').blur(function(){ // $(this).css('background','red'); // }); // $('input').focus(function(){ // $(this).css('background','blue'); // // }) // $('input').change(function(){ // $('input').css('background','pink'); // }) // $('button').click(function(){ // $('div').css('background','blue') // }); // $('div').dblclick(function(){ // $(this).css('background','red') // }); $(document).mousemove(function(aa){ $('span').text('x:'+aa.pageX+'y:'+aa.pageY); }) a = 0; $(window).resize(function(){ $('b').text(a+=1); }) }) </script> <input type="text" name=""> <button>改變</button> <div style="width:100px;height:100px;background:#f0f"></div> <div> 當(dāng)前鼠標(biāo)的位置是<span></span></div> <div> 頁面調(diào)整大小次數(shù)<b></b></div> </body> </html>