jQuery:同时选择一个元素的类和id? [英] jQuery: select an element's class and id at the same time?
问题描述
我有一些链接要同时选择类和 id.
I've got some links that I want to select class and id at the same time.
这是因为我有两种不同的行为.当一类链接有一个类名时,它们以一种方式表现,当相同的链接类得到另一个类名时,它们的行为不同.类名用jquery切换.
This is because I've got 2 different behaviours. When a class of links got one class name they behave in one way, when the same clas of links got another class name they behave differently. The class names are switch with jquery.
所以我必须能够同时选择链接类和 id.这可能吗?
So I have to be able to select a links class AND id at the same time. Is this possible?
我试过了:
$("a .save #country")
没有任何结果.
推荐答案
你可以这样做:
$("#country.save")...
或
$("a#country.save")...
或
$("a.save#country")...
随你喜欢.
所以是的,您可以指定一个选择器,该选择器必须匹配 ID 和 类(以及可能的标签名称和您想要输入的任何其他内容).
So yes you can specify a selector that has to match ID and class (and potentially tag name and anything else you want to throw in).
这篇关于jQuery:同时选择一个元素的类和id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!