jQuery多个选择器,获取哪个选择器触发事件 [英] jQuery multiple selectors, get which selector triggered event

查看:96
本文介绍了jQuery多个选择器,获取哪个选择器触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理具有多个选择器的事件时,例如:

When handling events with multiple selectors, such as:

$('.item a, .another-item a').click(function(e) {

});

是否可以确定哪个父选择器触发了事件?是 .item 还是 .another-item

Is it possible to determine which parent selector triggered the event? Was it .item or .another-item ?

谢谢你!

推荐答案

由于选择器可以是任何东西,你必须检查具体的,例如:

Since a selector can be just about anything, you'd have to check for specific, such as:

if($(this).is('.item a')){
  //your code here
} else if ($(this).is('.another-item a')){
  //more here
}

这篇关于jQuery多个选择器,获取哪个选择器触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆