我有 $("#notifications_list, .opt_notifications_parent")
然后我正在使用 $(this)
。现在我需要检查 $(this)
是第一个选择器还是第二个。
我该怎么做?
我试过类似的方法,但行不通:
if ($(this) == 'opt_notifications_parent'){
console.log("test");
}
最佳答案
您可以使用 hasClass()
if ($(this).hasClass('opt_notifications_parent'))
或is() (这是一个更昂贵的操作,所以使用 hasClass)
if ($(this).is('.opt_notifications_parent'))
关于javascript - 获取 $(this) 的类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32491141/