我有一個數組可以動態生成Div。現在我想隱藏&顯示div和1 div應該一次顯示並顯示下一個div用戶必須單擊button.something這樣的:在PHP中動態顯示/隱藏Div
<?php $h=0;?>
<script stype="textjavascript">
function test() {
document.getElementById("set").style.display="none";
document.getElementById("set<?php echo $h+1; ?>").style.display="block";
}
</script>
<?php
foreach($sets as $set){
if($h==0)
{
?>
<div id="set">
</php } else { ?>
<div id="set<?php echo $h;?>" style="display:none;">
<p><a class="continue" href="#" onclick="test()">Continue</a></p>
</div>
<?php $h++; } } ?>
現在使用上面的代碼,我可以能夠隱藏和顯示2格,但在3個DIV它是不工作的情況下,請讓我知道我做錯了。
好的,謝謝..你有什麼想法嗎? –
OP正在使用Javascript,這已經足夠了。 – irrelephant
這不是一個真正的答案。他已經在使用javascript來隱藏/顯示元素。他通過PHP輸出div。爲什麼要通過javascript輸出它們更合乎邏輯? – CharliePrynn