javascript - 带有共享修饰符的 jQuery "OR"选择器?

标签 javascript jquery

比如有没有更短的方法

$("td:nth-child(2),th:nth-child(2)").hide()

我尝试了 $("td,th").hide(":nth-child(2)") 但这不起作用。有人对此有想法吗?谢谢!

最佳答案

使用.filter()

$("td,th").filter(":nth-child(2)").hide();

.过滤器(选择器)

Description: Reduce the set of matched elements to those that match the selector or pass the function's test.

关于javascript - 带有共享修饰符的 jQuery "OR"选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18616768/

相关文章:

javascript - (tumblr) 如果帖子上没有注释,如何隐藏 {NoteCount}?

javascript - 如何在下拉列表中为选项添加附加值,以及如何在 angular js 1.x 中选择选项时获取该值

javascript - 只有第一页在 phonegap 中加载 javascript

javascript - 替换列文本值

javascript - 单击按钮时拼接不移除

javascript - 在 ajax 回调中更改 div 颜色

Javascript:使用正则表达式将字符串转换为数组

javascript - 如何将日期字符串与正则表达式匹配

c# - 动态生成 jQuery 函数 mvc 4 razor

javascript - 在 jQuery 中访问私有(private)变量的问题,如可链接设计模式