我有這樣的代碼:JavaScript的PHP內while循環
<?php
$i=5;
while($i > 0){
echo '
<table width="500px" border="1">
<tr>
<td>
<button id="button">Show comments</button>
</td>
</tr>
<tr>
<td id="comments" style="display:none;height:300px;width:100%;"></td>
</tr>
</table>
<script type="text/javascript">
$("#button").toggle(
function(){
$("#button").text("Hide Comments");
document.getElementById("comments").style.display="inline";
},function(){
$("#button").text("Show Comments");
document.getElementById("comments").style.display="none";
}
);
</script>
<script type="text/javascript" src="jquery.js"></script>
';
$i--;
}
?>
當點擊顯示評論按鈕評論框應顯示出來。它適用於第一個。但它對其他人不起作用。怎麼了?
您的循環似乎具有相同的ID輸出的元素...這是無效的 – dakait
'id'應該是唯一的 –
什麼有#show ID?那是在按鈕上?它應該是show-0,show-1等或一類節目。此外,你需要指定第二個與第二個東西等等 – scottheckel