【问题标题】:Why ":last" and ":last-child" does not work?为什么 ":last" 和 ":last-child" 不起作用?
【发布时间】:2013-09-05 20:46:44
【问题描述】:

我正在尝试在 id 为 a 的 div 中选择类 my_class 的最后一个 div。
我用:last:last-child 尝试了几个选项,但都没有奏效。
Here is on try.

我做错了什么?

【问题讨论】:

  • 我遇到了类似的问题。我用 .last() 代替。

标签: jquery html css css-selectors


【解决方案1】:

您的选择器有效,只是您的小提琴中没有包含 jQuery,这是一个更新/修复的版本:http://jsfiddle.net/eU7By/3/

在左侧面板上,确保选择 jQuery 作为您的库,默认情况下它是包含在内的 MooTools...毕竟它是由 MooTools 人构建的 :)

【讨论】:

    【解决方案2】:

    这应该适合你:

    $("#a div.my_class:last");
    

    fiddled -- 哦,您的示例不起作用的原因是您将 jsFiddle 设置为 MooTools,而不是 jQuery。

    【讨论】:

      【解决方案3】:

      看起来您在左侧选项中选择了 MooTools 而不是 jQuery。

      【讨论】:

        猜你喜欢
        • 2013-09-26
        • 2011-03-20
        • 1970-01-01
        • 2013-05-30
        • 1970-01-01
        • 2012-05-26
        • 2014-08-07
        • 1970-01-01
        • 2020-09-11
        相关资源
        最近更新 更多