abstract:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=, initial-scale=
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
// 在jQuery中是以調(diào)用事件函數(shù)的形式來(lái)觸發(fā)事件的,如js中的onclick事件,在jQuery則用click()來(lái)替代
// 簡(jiǎn)單的理解:事件方法會(huì)觸發(fā)匹配元素的事件,或者將函數(shù)綁定到所有匹配元素的某個(gè)事件
//ready() 當(dāng)我們的DOM已經(jīng)加載,頁(yè)面已經(jīng)加載完,觸發(fā)的事件==js的onload
//語(yǔ)法:
// $(document).ready(function(){
// })
//*不能與<body onload="">一起使用
//blur()當(dāng)元素失去焦點(diǎn)==onblur
// focus()當(dāng)元素獲得焦點(diǎn)
// change()當(dāng)元素的值發(fā)生改變的時(shí)候
// click()點(diǎn)擊事件
//dblclick()雙擊事件
// mouseover() 當(dāng)鼠標(biāo)指針位于元素上方時(shí)會(huì)發(fā)生mouseover事件
// mouseenter() 當(dāng)鼠標(biāo)指針穿過(guò)元素時(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í)
// mousedown() 當(dāng)鼠標(biāo)指針移動(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ù)來(lái)自事件綁定函數(shù)。
// pageY() 屬性是鼠標(biāo)指針的位置,相對(duì)于文檔的上邊緣 event.pageY event:必需 參數(shù)來(lái)自事件綁定函數(shù)。
<script>
$(document).ready(function(){
$('button').click(function(){
$('div').toggle()
})
})
$(document).mousemove(function(aa){
$('span').text('x'+aa.pageX+'Y'+aa.pageY)
})
a=0
$(window).resize(function(){
$('b').text(a++)
})
$('input').focus(function(){
$('input').css('background','blue')
})
</script>
<div style="width: 100px;height: 100px;background:pink;"></div>
<button>點(diǎn)擊</button>
<div>當(dāng)前鼠標(biāo)位置:
<span></span>
</div>
<div>頁(yè)面被調(diào)整次數(shù): <b></b></div>
<input type="text">
</body>
</html>
Correcting teacher:天蓬老師Correction time:2019-08-22 15:33:33
Teacher's summary:jQuery官方推薦使用on()和off()來(lái)綁定或取消事件, 如果直接用click, 只支持冒泡, 并且 同一事件只能觸發(fā)一次