Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么当我点击超链接时,它会隐藏所有的东西而不是相关的东西?_Javascript_Jquery_Html_Hyperlink_Show Hide - Fatal编程技术网

Javascript 为什么当我点击超链接时,它会隐藏所有的东西而不是相关的东西?

Javascript 为什么当我点击超链接时,它会隐藏所有的东西而不是相关的东西?,javascript,jquery,html,hyperlink,show-hide,Javascript,Jquery,Html,Hyperlink,Show Hide,我显示了一个问题列表,以及他们的答案和正确答案。为此,我正在使用HTML。现在,每个题为“隐藏显示答案”的问题中都有一个超链接。当用户点击这个超链接时,“选项”标题、问题选项和正确答案应该隐藏起来。如果这些东西是隐藏的,那么点击超链接就会显示出来。最初,当页面加载时,所有内容都应该像现在一样显示。还有一件事是,当页面最初加载时,所有内容都会显示给用户,超链接的文本应该是隐藏的,当用户单击此链接时,内容应该隐藏,标题应该更改为显示答案。以下是我的问题表的HTML: <table ce

我显示了一个问题列表,以及他们的答案和正确答案。为此,我正在使用HTML。现在,每个题为“隐藏显示答案”的问题中都有一个超链接。当用户点击这个超链接时,“选项”标题、问题选项和正确答案应该隐藏起来。如果这些东西是隐藏的,那么点击超链接就会显示出来。最初,当页面加载时,所有内容都应该像现在一样显示。还有一件事是,当页面最初加载时,所有内容都会显示给用户,超链接的文本应该是隐藏的,当用户单击此链接时,内容应该隐藏,标题应该更改为显示答案。以下是我的问题表的HTML:

    <table cellpadding="0" cellspacing="0" border="0" width="98%" style="padding:0 10px 0 10px;" align="center">
          <tbody>

            <tr>
              <td>
                <div class="sub_name" id="" >
                  <div style="height:800px; overflow:scroll; width:100%;">
                      <table cellpadding="5" cellspacing="0" border="0" width="100%" class="manage_box"> 
                      <tr class="question_info">
                        <td valign="top">
                          <b>Question 1.<a href ="#" style="margin-left:300px;" class="fav_que" id="15957">Add To Favourite Question</a></b><br /><b>Direction : </b><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">


                          <br /><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 dimensions of universal gravitational constant are</p></body></html>
                                                                              <br/><b>QUE15957</b><br/>
                          <a href="#" class="show-ans">Hide-Show Answers</a> 
                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Options : </b>
                        </td>
                      </tr>
                                                                  <tr>
                        <td class="options" colspan="2">                     1 .

M-2L2T-2

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     2 .

M-1L3T-2

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     3 .

ML-1T-2

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     4 .

ML2T-2

                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Correct Answer :</b> 2   
                        </td>
                      </tr>              
                                      </table>
                            <table cellpadding="5" cellspacing="0" border="0" width="100%" class="manage_box"> 
                      <tr class="question_info">
                        <td valign="top">
                          <b>Question 2.<a href ="#" style="margin-left:300px;" class="fav_que" id="37672">Add To Favourite Question</a></b><br /><b>Direction : </b><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">


                          <br /><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>If angular momentum quantum number can take value of <i>n</i> also (in addition to other possible values) then total number of electrons in first orbit would have been :</p></body></html>
                                                                              <br/><b>QUE37672</b><br/>
                          <a href="#" class="show-ans">Hide-Show Answers</a> 
                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Options : </b>
                        </td>
                      </tr>
                                                                  <tr>
                        <td class="options" colspan="2">                     1 .

2

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     2 .

6

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     3 .

8

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     4 .

10

                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Correct Answer :</b> 3   
                        </td>
                      </tr>              
                                      </table>
                            <table cellpadding="5" cellspacing="0" border="0" width="100%" class="manage_box"> 
                      <tr class="question_info">
                        <td valign="top">
                          <b>Question 3.<a href ="#" style="margin-left:300px;" class="fav_que" id="38552">Add To Favourite Question</a></b><br /><b>Direction : </b><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">


                          <br /><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>For figure 24, the correct relation is -<br><img height="110" src="http://www.entranceprime.com/upload_media/questions/original/1328941281_38.JPG" width="172"></p></body></html>
                                                                              <br/><b>QUE38552</b><br/>
                          <a href="#" class="show-ans">Hide-Show Answers</a> 
                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Options : </b>
                        </td>
                      </tr>
                                                                  <tr>
                        <td class="options" colspan="2">                     1 .

<img src="http://localhost/eprime/entprm/web/ckeditor_3.6.1/plugins/ckeditor_wiris/integration/showimage.php?formula=9329a28849bd94b3bcc49e3a4b69a595.png" class="Wirisformula" align="middle">

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     2 .

<img src="http://localhost/eprime/entprm/web/ckeditor_3.6.1/plugins/ckeditor_wiris/integration/showimage.php?formula=c8c15583e8f5742625e6d80c71f3a691.png" class="Wirisformula" align="middle">

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     3 .

<img src="http://localhost/eprime/entprm/web/ckeditor_3.6.1/plugins/ckeditor_wiris/integration/showimage.php?formula=af6f96bda5c2f575fc42e4751c5772fe.png" class="Wirisformula" align="middle">

                        </td>
                      </tr>
                                            <tr>
                        <td class="options" colspan="2">                     4 .

All of the above

                        </td>
                      </tr>
                                            <tr>
                        <td colspan="2">
                          <b>Correct Answer :</b> 4   
                        </td>
                      </tr>              
                                      </table>

                        </div>
              </div>
            </td>
          </tr>

        </tbody>
      </table>

现在我的问题是当我点击一个特定问题的超链接时,只有它的选项和正确的选项应该隐藏。其他问题的内容应按原样显示,但事实并非如此。当我点击一个特定问题的超链接时,所有内容都被隐藏,包括我点击的超链接。如何更正此问题?

以这种方式更改代码

$(".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 Answer");
  }
  else
  {
      $(this).parent().parent().parent().children("tr:not(:first)").show();
  $(this).html("Hide Answer");
  }
 });

您的标记无效,请检查它是否正常工作。对你的答案投了赞成票。我很快就会接受的。谢谢你的帮助。:现在我的要求略有改变。我想保持隐藏的内容,我是根据前面的要求在表单加载显示。你能告诉我如何做到这一点吗?这对我会有很大的帮助。你能把它作为另一个问题再解释一下吗?事实上你的答案对我来说很有用。我也接受了。但现在我的要求是,我希望在最初显示表单时隐藏内容。然后单击超链接,我想隐藏/显示内容。内容包括选项标题、实际选项和该问题的正确答案。同样,对于所有问题,这些东西最初应该隐藏在表单加载中。但当用户点击相关问题的超链接时,它应该只对现在有效的问题有效。在这方面你能帮我吗?我发布了一个新问题。链接或ot如下所示:
$(".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 Answer");
  }
  else
  {
      $(this).parent().parent().parent().children("tr:not(:first)").show();
  $(this).html("Hide Answer");
  }
 });