【问题标题】::nth-child() selector, multiple nth-child:nth-child() 选择器,多个 nth-child
【发布时间】:2013-04-04 12:04:30
【问题描述】:

我正在尝试在表头上获取单击事件,这很容易使用 jQuery。 我希望单击事件在除第一个标题之外的所有标题上都处于活动状态。

我正在使用 CSS 的 :nth-child() 属性转义第一个标题。

这就是我正在做的-

$(function(){
$('th:nth-child(2 3 4 5)').click(function(){
$(this).CSS("font-weight","bolder");
});
});

我没有得到结果。 :nth-child() 本身有什么更好的方法吗?

【问题讨论】:

    标签: jquery css jquery-selectors css-selectors


    【解决方案1】:

    您可以使用:not

    $('th:not(:first-child)').click(function(){
    

    你可以使用:gt(0)

    $('th:gt(0)').click(function(){
    

    评论回复

    对于奇数选择器,您可以使用:odd jQuery 选择器。

    Official Document

    示例

    $('th:not(:odd)').click(function(){
    

    【讨论】:

    • 一切顺利,所以如果我只想选择odd childs,那么我应该这样做-:nth-child(:odd-child) 还是一样?
    • @Manoz thanx 很高兴我能帮到你。
    【解决方案2】:

    怎么样

    $('th:nth-child(n+2)')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      相关资源
      最近更新 更多