【问题标题】:Select all elements in between two tags of the same type?选择相同类型的两个标签之间的所有元素?
【发布时间】:2011-06-11 02:33:38
【问题描述】:

如何使用 javascript 或 jquery 选择相同类型的两个标签之间的所有元素?

例如,如果我有:

<h1></h1>
<h2><h2>
<li1></li1>
<li2></li3>
<li3></li4>
<h2></h2>

我怎样才能得到所有的&lt;li&gt;

我尝试使用这个$units=$(this).nextuntil("h2");,但没有用

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:
    $('h2:first').nextUntil('h2:last');
    

    演示:http://www.jsfiddle.net/4yUqL/63/

    这当然只适用于这个特定的例子。在更复杂的标记中,您可能需要更具体。像 $('h2:eq(2)') 或其他伪选择器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-23
      • 2012-06-07
      • 2022-11-18
      • 1970-01-01
      • 2011-02-11
      相关资源
      最近更新 更多