我有这个代码:
<div class="window-compl">
<div class="window showincatalog showing">
<h2>Text1</h2>
</div>
<div class="window">
<h2>Text2</h2>
</div>
<div class="window showincatalog">
<h2>Text3</h2>
</div>
<div class="window showincatalog">
<h2>Text4</h2>
</div>
</div>
我在此函数中使用 jquery 选择器 next() 和 prev():
function rotate(direction) {
var current = $('.showing');
if (direction==0)
var next = $('.showing').prev('.showincatalog');
else
var next = $('.showing').next('.showincatalog');
}
当所有 div 标签都具有 showincatalog 类时,它会起作用,但当其中一个标签不具有类时,它会停止。
如果有人知道为什么这不起作用,那就太好了
更新:我需要选择带有“showincatalog”类和 Text3 的 div,但 $('.showing').next('.showincatalog') 不返回任何内容。
最佳答案
我想我明白你想要做的事情,但我自己也被这个刺痛了。诀窍在于 next
要么获取下一个元素,要么什么也不获取。如果您想要“匹配此选择器的下一个元素”,请使用 .nextAll('selector').first()
。
关于javascript - Jquery next() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5435580/