【发布时间】:2014-05-26 01:09:31
【问题描述】:
我正在尝试为特定应用程序开发一种幻灯片。我在要显示的 div 的增量方面遇到了一些问题。 我需要传递选择器及其位置,然后增加它的位置。
检查我需要做什么的代码:
HTML:
<div name="div-default" class="title-result">
<?php
echo "$name";
?>
</div>
<div name="div01" id="div01" class="title-result">
<?php
echo "Seu número de Personalidade é: $numerologia[0]";
?>
</div>
<div name="div02" class="title-result">
<?php
echo "Seu número de Destino é: $numerologia[1]";
?>
</div>
<div name="div03" class="title-result">
<?php
echo "Seu número de Lição de Vida é: $numerologia[2]";
?>
</div>
<div>
<button onclick="mudarDivNext([name ^= div0]:nth-child(SEND_ITS_POSITION_HERE))" id="next" class="change-div"></button>
</div>
CSS:
//here i define that the first div is visible, and the next ones invisible
div[name ^= div0]:nth-child(2){
display: inherit;
}
div[name ^= div0]{
display: none;
}
Javascript:
//This script already works for a fix position (from 2 for 3, for example) - need to make it work for all the divs.
function mudarDivNext(){
var n = 2;
$("[name ^= div0]:nth-child("+n+")").css("display", "none");
$("[name ^= div0]:nth-child("+(n+1)+")").css("display", "inherit");
}
【问题讨论】:
-
是的,有可能,你试过了吗?
-
是的,我做到了.. 它在这里不起作用。我不知道如何发送我的 div 位置的编号 ([name ^= div0]:nth-child(2);[name ^= div0]:nth-child(3); [name ^= div0] :nth-child(4))...
标签: javascript css jquery-selectors css-selectors selector