2010-01-06 32 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 
    } 

    }); 
相关问题