標籤:doc 源碼 handle func hello 屬性 script class png
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="jquery-2.0.3.js"></script><script>jQuery.event = { global 事件的全域屬性(源碼還沒用到) add 綁定事件 remove 取消事件 trigger 主動觸發事件 dispatch 配發事件的具體操作 handlers 函數執行順序的操作 props JQ中共用原生JS的event屬性 fixHooks 收集event相容的集合 keyHooks 鍵盤的event相容 mouseHooks 滑鼠的event相容 fix event對象的相容處理 special 特殊事件的處理 simulate focusin的類比操作(trigger , dispatch)};jQuery.Event = function(){};jQuery.Event.prototype = { isDefaultPrevented isPropagationStopped isImmediatePropagationStopped preventDefault stopPropagation stopImmediatePropagation};jQuery.fn.extend({ on one off trigger triggerHandler});//6720.click();.mouseover();jQuery.fn.extend({ hover bind unbind delegate undelegate});$(function(){ $(‘#div1‘).on(‘click‘,function(){ alert(123); }); $(‘#div1‘).on(‘click‘,{name:‘hello‘},function(ev){ alert(ev.data.name); });----------------------------------------------------------------------- //ul要是li的父級或者主線節點 /* delegate: function( selector, types, data, fn ) { return this.on( types, selector, data, fn );//this=$(‘ul‘) }, */ $(‘ul‘).delegate(‘li‘,‘click‘,{name:‘hello‘},function(){ $(this).css(‘background‘,‘red‘);//點擊li,li變紅,這個點擊其實是ul身上,通過委託加到了li身上 }); $(‘ul‘).on(‘click‘,‘li‘,{name:‘hello‘},function(){//這也是委託,on有selector就是委託 $(this).css(‘background‘,‘red‘); });----------------------------------------------------------------------- $(‘#div1‘).on(‘click‘,function(){ alert(123); }); $(‘#div1‘).on(‘mouseover‘,function(){ alert(456); }); $(‘#div1‘).on({ ‘click‘ : function(){ alert(123); }, ‘mouseover‘ : function(){ alert(456); } });----------------------------------------------------------------------- $(‘#div1‘).one(‘click‘,function(){//只執行一次 alert(123); });------------------------------------------------------------------- $(‘#input1‘).focus(function(){ $(this).css(‘background‘,‘red‘); }); $(‘#input1‘).trigger(‘focus‘);//觸發focus事件 $(‘#input1‘).triggerHandler(‘focus‘); //觸發focus事件,但是游標不會移進去,不會觸發當前事件的預設行為 });</script></head><body><div id="div1">div</div><ul> <li>11111</li> <li>11111</li> <li>11111</li> <li>11111</li></ul><input type="text" id="input1"></body></html>
jquery14 on() trigger() : 事件操作的相關方法