jquery14 on() trigger() : 事件操作的相關方法

來源:互聯網
上載者:User

標籤: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() : 事件操作的相關方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.