我正在尝试使用jquery的.nextUntil()方法之后选择第二个元素。如何选择选择器元素之后的第二个元素?
我已经尝试使用Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/ConfigurationException
at com.datastax.spark.connector.streaming.DStreamFunctions.saveToCassandra$default$4(DStreamFunctions.scala:47)
at com.StreamingPrerequisiteLoad$.main(StreamingPrerequisiteLoad.scala:72)
at com.StreamingPrerequisiteLoad.main(StreamingPrerequisiteLoad.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.ConfigurationException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
和.nextUntil(".headerRow", "tr:odd")
这是我要开始工作的代码行:
.nextUntil(".headerRow", "tr:nth-child(odd)")
它每秒钟选择一次$('.headerRow').nextUntil(".headerRow", "tr:nth-child(odd)").css("background-color", "rgb(240,240,240)");
...但是它是基于整个表而不是最后一个tr
它看起来像:
.headerRow
它应该像这样开始选择<tr> - (not selected)
<tr> - (not selected)
<tr> - (not selected)
<tr class="headerRow"> - (not selected)
<tr> - (selected)
<tr> - (not selected)
<tr class="headerRow"> - (not selected)
<tr> - (not selected) <----- should be selected
<tr> - (selected) <------ shouldn't be selected
<tr> - (not selected) <----- should be selected
<tr class="headerRow"> - (not selected)
<tr> - (selected)
<tr> - (not selected)
...
:
<tr>
我该如何解决?
编辑:像这样生成表:
<tr> - (not selected, ok)
<tr> - (not selected, ok)
<tr> - (not selected, ok)
<tr class="headerRow"> - (not selected)
<tr> - (selected)
<tr> - (not selected)
<tr class="headerRow"> - (not selected)
<tr> - (selected)
<tr> - (not selected)
<tr> - (selected)
<tr class="headerRow"> - (not selected)
<tr> - (selected)
<tr> - (not selected)
...
答案 0 :(得分:3)
仅使用:odd, :even
很难实现,因为偶数是其绝对顺序的引用。
因此,您首先需要进行分组-在应用几率和偶数之前-这将成为该组的相对。
这是使用.each()
的一个示例:
$('.headerRow').each(function() {
$(this).nextUntil('.headerRow', 'tr:even').css('background', 'red');
});
<table>
<tr><td>no</td></tr>
<tr><td>no</td></tr>
<tr><td>no</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr><td>sel</td></tr>
<tr><td>no</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr><td>sel</td></tr>
<tr><td>no</td></tr>
<tr><td>sel</td></tr>
<tr><td>no</td></tr>
<tr><td>sel</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr class="headerRow"><td>---HR no---</td></tr>
<tr><td>sel</td></tr>
<tr><td>no</td></tr>
</table>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
$(this).nextUntil('.headerRow')
是我们的迭代小组。