我正在使用 jquery 在我的页面上实现事件委托(delegate)。我为顶级元素定义了一个点击处理程序,但如果点击落在某个类的元素上,我只想做一些“自定义”:
$("#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”?
感谢您的任何帮助,
劳拉
最佳答案
编写一个处理函数,然后在 else 中引用它:
$("#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
}
关于javascript - 从我的自定义点击处理程序调用默认事件处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2015581/