2010-01-06 62 views
1

我正在使用jquery在我的頁面上實現事件委託。我定義爲頂級元素的單擊處理程序,而只是想要做的事「定製」如果點擊某個下跌類的元素:從我的自定義點擊處理程序調用默認事件處理程序?

$("#myDivWithManyLinks").click(function(e){ 
    var target = $(e.target); 
    if (target.hasClass('myClass123') 
    { 
     // do my "custom thing" 
     return false; 
    } 
    else 
    { 
     // XXX let the click be handled by the click handler that would otherwise get it 
    } 

我該怎麼辦「XXX」?

感謝您的幫助,

拉拉

+0

你這是什麼意思是「我怎麼做XXX」?如果目標沒有class myClass123,則XXX將運行。 – David 2010-01-06 19:31:55

回答

0

寫一個處理函數,然後引用它在其他:

$("#myDivWithManyLinks").click(function(e){ 
    var target = $(e.target); 
    if (target.hasClass('myClass123') 
    { 
     // do my "custom thing" 
     return false; 
    } 
    else 
    { 
     handler(e); 
    } 
    }); 
    function handler(e){ 
     // what you want all links that don't have your special class to do 
    } 
0

怎麼樣preventDefault()

$("#myDivWithManyLinks").click(function(e){ 
    var target = $(e.target); 
    if (target.hasClass('myClass123') 
    { 
     e.preventDefault(); 
     //do custom stuff 
    } 

    });