我试图弄清楚如何获取特定 div 的 index() 值……</p>
基本 HTML:
<div class="rsContainer">
<div class="rsSlide rsActiveSlide">
<div class="rsContent" data-name="/A"></div>
</div>
<div class="rsSlide">
<div class="rsContent" data-name="/B"></div>
</div>
<div class="rsSlide">
<div class="rsContent" data-name="/C"></div>
</div>
<div class="rsSlide">
<div class="rsContent" data-name="/D"></div>
</div>
<div class="rsSlide">
<div class="rsContent" data-name="/E"></div>
</div>
<div class="rsSlide">
<div class="rsContent" data-name="/F"></div>
</div>
</div>
所以这里是我尝试过的代码:
var pathname = B;
// this is a random one of the data-name values
var currentslide = $(".rsActiveSlide").find(".rsContent").data("name");
// this is active
var rightone = $(".rsContainer").find(".rsContent" + "[data-name='" + pathname +"']");
// this should be the active
// here is the problem, all i need is the index(); of the parent.DIV (.rsSlide)
if (currentslide != pathname) {
goTo(index-of-rightone's-parent);
}
// so i could do: goTo(index); and the Slider will set the Slide which contains the "rightone" to be active
非常感谢你!任何帮助表示赞赏...</p>
wbr 狮子座