abstrakt:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jquery事件方法2</title> <script type="text/javascript" src="
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jquery事件方法2</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $(document).mousemove(function(aa){ $("span").text("x:"+aa.pageX+"y:"+aa.pageY) }) a=0 $(window).resize(function(){ $("b").text(a++) }) $(".one").mouseenter(function(){ $(".one").css("background","blue") }) $(".two").mouseover(function(){ $(".two").css("width","50px") }) $(".three").mouseout(function(){ $(".three").css("height","50px") }) $(".four").mousedown(function(){ $(".four").css({"width":"50px","height":"50px"}) }) $(".five").mouseup(function(){ $(".five").css({"width":"200px","height":"200px","background":"green"}) }) }) </script> <div>當(dāng)前鼠標(biāo)的位置:<span></span></div> <div>頁面被調(diào)整大小的次數(shù):<b></b></div> <div style="width:100px;height: 100px;background: red"></div><br> <div style="width:100px;height: 100px;background: red"></div><br> <div style="width:100px;height: 100px;background: red"></div><br> <div style="width:100px;height: 100px;background: red"></div><br> <div style="width:100px;height: 100px;background: red"></div><br> </body> </html> mouseover() 當(dāng)鼠標(biāo)指針位于元素上方時會發(fā)生mouseover事件 mouseenter() 當(dāng)鼠標(biāo)指針穿過元素時會發(fā)生mouseenter事件 mousemove() 當(dāng)鼠標(biāo)指針在指定的元素中移動時,就會發(fā)生mousemove事件 mouseleave() 當(dāng)鼠標(biāo)指針離開元素時,就會發(fā)生mouseleave mouseout() 當(dāng)鼠標(biāo)指針從元素上移開時,就會發(fā)生mouseout mousedown() 當(dāng)鼠標(biāo)指針移動到元素上方并按下按鍵時) mouseup() 當(dāng)在元素上松開鼠標(biāo)按鍵時 resize() 當(dāng)調(diào)整當(dāng)前瀏覽器窗口大小時 pageX() 屬性是鼠標(biāo)指針的位置,相對于文檔的左邊緣 event.pageX event:必需 參數(shù)來自事件綁定函數(shù) pageY() 屬性是鼠標(biāo)指針的位置,相對于文檔的右邊緣 event.pageY event:必需 參數(shù)來自事件綁定函數(shù) $(".four").mousedown(function(){ $(".four").css({"width":"50px","height":"50px"}) }) // 在改變多個屬性的時候, 1、每個屬性,和屬性值都要有引號, 2、屬性和屬性對應(yīng)的屬性值之間有冒號, 3、一定要有花括號將多個屬性包起來 在寫選擇器的時候,一定要定位準(zhǔn)確,因為有多個div,沒有準(zhǔn)確 定位的話,容易出錯。