以下は、ページで div ブロックを表示/非表示にするために使用している完全なコードです。現在、特定のテキスト見出しをクリックすると、その見出しのブロック コンテンツが表示されます。次に、別のテキスト見出しをクリックすると、その見出しの別のブロック コンテンツが表示されますが、以前に開いたブロックは閉じません。別の見出しをクリックするたびに、開いているブロックを閉じたい。私を助けてください。
function viewdetail(divno)
{
if(document.getElementById("div_com"+ divno).style.display=="block")
{
document.getElementById("div_com"+ divno).style.display="none";
document.getElementById("a_title"+ divno).title="Click to view details";
}
else
{
document.getElementById("div_com"+ divno).style.display="block";
document.getElementById("a_title"+ divno).title="Click to hide details";
}
return true;
}
<table>
<?php
$int_cnt=1;
while(!$rs_list->eof())
{
?>
<tr>
<td>
<a name="a<?php print($int_cnt)?>"></a>
<table>
<tr>
<td><a href="#a<?php print($int_cnt)?>" id="a_title<?php print($int_cnt)?>" onClick="return viewdetail(<?php print($int_cnt)?>);"><?php print($rs_list->fields("title"));?></a></td>
</tr>
<tr>
<td>
<div align="justify" id="div_com<?php print($int_cnt)?>" style="display:none"><table><tr><td>Text will display here</td></tr></table></div>
</td>
</tr>
</table>
</td>
</tr>
<?php
$rs_list->movenext();
$int_cnt=$int_cnt+1;
}
?>
</table>