我正在使用 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/