綁定事件方式:
$(function(){
$('#div1').bind('mouseover click', function(event) {
alert($(this).html());
});
});
取消綁定事件方式:
$(function(){
$('#div1').bind('mouseover click', function(event) {
alert($(this).html());
});
});
事件函數列表:
blur() 元素失去焦點
focus() 元素獲得焦點
change() 表單元素的值發(fā)生變化
click() 鼠標單擊
dblclick() 鼠標雙擊
mouseover() 鼠標進入(進入子元素也觸發(fā))
mouseout() 鼠標離開(離開子元素也觸發(fā))
mouseenter() 鼠標進入(進入子元素不觸發(fā))
mouseleave() 鼠標離開(離開子元素不觸發(fā))
hover() 同時為mouseenter和mouseleave事件指定處理函數
mouseup() 松開鼠標
mousedown() 按下鼠標
mousemove() 鼠標在元素內部移動
keydown() 按下鍵盤
keypress() 按下鍵盤
keyup() 松開鍵盤
load() 元素加載完畢
ready() DOM加載完成
resize() 瀏覽器窗口的大小發(fā)生改變
scroll() 滾動條的位置發(fā)生變化
select() 用戶選中文本框中的內容
submit() 用戶遞交表單
toggle() 根據鼠標點擊的次數,依次運行多個函數
unload() 用戶離開頁面
自定義事件:
除了系統(tǒng)事件外芬迄,可以通過bind方法自定義事件问顷,然后用tiggle方法觸發(fā)這些事件。
//給element綁定hello事件
element.bind("hello",function(){
alert("hello world!");
});
主動觸發(fā)事件:
可使用jquery對象上的trigger方法來觸發(fā)對象上綁定的事件禀梳。
//觸發(fā)hello事件
element.trigger("hello");