jQuery 还是选择器?
只是想弄清楚如何在现有代码段中测试多个选择器,即像这样
if (!(jQuery('#selector1 || #selector2').hasClass('some-class'))) {
//code here
}
这不起作用,但想知道我是否可以做些什么来使其工作?
Just trying to figure out how you can test multiple selectors within an existing piece of code i.e. like this
if (!(jQuery('#selector1 || #selector2').hasClass('some-class'))) {
//code here
}
This doesn't work but wondering if there is anything I can do to make it work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需选择它们,如果其中任何一个具有类
some-class
,则条件为真:或者,如果我误解了您的逻辑,您可以(并且应该,为了速度和简单性)中断那些一分为二:
Just select them both, if either of them has the class
some-class
, the condition is true:Or, if I misinterpreted your logic, you can (and should, for sake of speed and simplicity) break those into two:
很简单,就是一个逗号;)
Quite simple, it's a comma ;)
据我所知没有。也许只是做这样的事情:
not that I know of. maybe just do something like this:
为什么不喜欢这样呢?
Why not like this?