我有一个显示 SQL 结果的表,但是我希望该表显示某些结果,并在单击时在表下方的 div 标记中显示更多结果。到目前为止,我有这段显示“标题”和“电子邮件”的代码以及将触发 JS 函数并在 div 标记中显示“详细信息”的第 3 列...如何使用 JavaScript 显示特定详细信息并隐藏单击第二行详细信息并替换第一行时的那些详细信息?
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><a href="#" onClick="moreDetails();">More details...</a></td>
</tr>
编辑: 在收到评论后,这是我的表格的完整代码,其中包含 id 为“details”的 div 元素
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><strong>Details</strong></td>
</tr>
<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><a href="#" onClick="viewInvestor();">More details...</a></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
</tr>
</table>
<div id="detail"></div>
最佳答案
我不确定这是否是你想要做的,但你可以尝试这样的事情。希望对您有所帮助
HTML
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><a href='#' id='show_details'>More Details</a></td>
</tr>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td id='details'><?php echo $rows['details'];?></td>
</tr>
</table>
Javascript - JQuery
$(document).ready(function()
{
$('#details').hide(); //on ready hide the td details
$('#show_details').click(function()
{
$('#details').show();
});
});
更新
你的意思是这样 SEE MY FIDDLE
关于php - 隐藏 sql 结果列并在单击时显示在下表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16974004/