jQuery中的事件
1:加載DOM
在JavaScript中使用window.onload事件作為窗體加載事件(它在頁面所有數(shù)據(jù)加載完成之后才會執(zhí)行)
在jQuery里面中使用 $(document).ready(function()) 作為窗體加載事件(在DOM加載完成之后就會執(zhí)行)
2:事件綁定
在文檔加載完成后,可以使用bind()方法來對匹配元素進行特定事件的綁定
bind(type [data],function)
例子:$("div").bind("mouseover mouseout click",function(){ })
unbind() 對匹配的元素進行移除事件的方法 unbind("type") type--事件類型
3:常用的事件
blur 失去焦點 focus 獲取焦點 focusin focusout load unload click dblclick mousedown mouseup
mousemove mouseover mouseout mouseenter mouveleave change select submit keydown keypress
keyup error
4: 阻止事件冒泡: event.stopPropagation()
5:觸發(fā)事件 trigger()
$("#id").trigger("click") 常用模擬觸發(fā)事件
6:事件對象的屬性
event.type ----獲取事件類型
event.stopPropagation() -----阻止事件冒泡
event.pageX ---獲取光標相對于頁面的X坐標
event.pageY --獲取光標相對于頁面的Y坐標
event.target --獲取事件源對象(獲取到觸發(fā)事件的元素)
event.which --在鼠標單擊事件中獲取鼠標的左中右鍵
event.metaKey --為鍵盤事件中獲取CTRL鍵
event.metaKey :jquery1.4以及之前CTRL按下為true 后續(xù)版本改為false

浙公網(wǎng)安備 33010602011771號