【发布时间】:2014-03-10 15:46:01
【问题描述】:
以下是我的 HTML 代码:
<div id="entrancelist">
<h2 class="heading">favourite questions</h2>
<table cellpadding="0" cellspacing="0" border="0" width="98%" style="padding:5px;" align="center">
<tbody>
<tr>
<td>
<div class="sub_name" id="" >
<div style="height:auto; overflow:hidden; width:100%;">
<table cellpadding="5" cellspacing="0" border="0" width="100%" class="manage_box">
<tr class="question_info">
<td valign="top" width="70%">
<b>Question 4.</b></td>
<td valign="top" align="left" width="30%">
<b><a href ="#" style="margin-right:0px;" class="fav_que" id="93041">Remove From Favourite Question</a></b></td></tr>
<tr class="question_info">
<td valign="top" colspan="2">
<br /><b>Direction : </b><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
</td></tr>
<tr class="question_info">
<td valign="top">
<b>Question : </b>
<br/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>The angel between <img align="middle" class="Wirisformula" src="http://localhost/eprime/entprm/web/ckeditor_3.6.1/plugins/ckeditor_wiris/integration/showimage.php?formula=527931a5749cffe312c126871736b88d.png"><br></p></body></html>
</td>
<td valign="bottom" align="right"><b>QUE93041</b></td>
</tr>
<tr class="question_info">
<td valign="top" colspan="2">
<a href="#" class="show-ans">Show Answers</a>
</td>
</tr>
</td>
</tr>
<tr>
<td colspan="2">
<b>Options : </b>
</td>
</tr>
<tr>
<td class="options" colspan="2"> 1 .
90o
</td>
</tr>
<tr>
<td class="options" colspan="2"> 2 .
between 0o and 180o
</td>
</tr>
<tr>
<td class="options" colspan="2"> 3 .
180o only
</td>
</tr>
<tr>
<td class="options" colspan="2"> 4 .
none of these
</td>
</tr>
<tr>
<td colspan="2">
<b>Correct Answer :</b> 2
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
这里我展示了问题、可用选项和正确答案。单击超链接,我将隐藏并显示可用选项和正确答案。它的代码如下:
$(document).ready(function() {
$(".show-ans").click(function(e) {
e.preventDefault();
if($(this).parent().parent().parent().children("tr:last").is(":visible")){
$(this).parent().parent().parent().children("tr:not(:first)").hide();
$(this).html("Show Answers");
} else {
$(this).parent().parent().parent().children("tr:not(:first)").show();
$(this).html("Hide Answers");
}
});
});
上面的代码也可以正常工作。我的问题是,当页面加载时,所有问题都应该隐藏这些东西,如果点击超链接,它应该隐藏,如果它正在显示,它应该在隐藏时显示。有人可以在这方面帮助我吗?
【问题讨论】:
-
你应该用 css 隐藏它,否则当它最初在慢速计算机/浏览器上加载时,答案会在页面上闪烁。
-
只需切换一个类...
-
Kevin B 是对的,你需要添加 display: hidden;到答案的css,而不是使用javascript在页面加载时隐藏它们
标签: javascript jquery html html-table show-hide