【发布时间】:2017-11-22 05:39:31
【问题描述】:
我正在尝试创建一个可扩展的常见问题解答页面。我在 stackoverflow 上提到了几个有答案的线程,但是当我在我的代码中实现它时,我无法获得页面上问题的可扩展答案。
当我点击问题时,它没有显示任何变化
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js">
</script>
<script>
<script type="text/javascript">
$(document).ready(function(){
$('.faqlink').click(function(){
$('.content').hide();
$(this).parent('td').next('.content').show();
});
});
</script>
<style type="text/css">
.content {
display: none;
}
</style>
</head>
<body>
<table>
<tr>
<td>
<a class="faqlink" href="#"><?php if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<h3><b>".$row["question"]." </b></h3>";
}
} else {
echo "0 results";
}
?></a>
<br><br>
</td>
<td class="content">
<?php if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<h3><b>".$row["answer"]." </b></h3>";
}
} else {
echo "0 results";
}
?>
<br><br>
</td>
</tr>
</table>
</div>
</body>
</html>
【问题讨论】:
-
这里的php代码没用。而是共享您的 HTML。当您询问内置
toggle的JQuery 时,为什么要使用style.display? -
document.getElementById(id).style.display = 'block'; -
我更新了问题中的代码
标签: javascript php jquery