提交表单后保留显示的div

时间:2014-09-22 08:12:49

标签: javascript jquery html css forms

我创建了3个使用输入类型按钮显示的div,这些按钮用于显示和隐藏最初隐藏的div。在这些div中有一些用于存储数据的表单。现在我要做的是在提交表单中的数据后保留当前使用的div。

这是我的jquery代码。

$("#add_exams").hide();
  $("#exams").hide();
  $("#add_accts").hide();

  $("#view_exam").click(function(){
      $("#add_exams").hide();
      $("#exams").hide();
      $("#add_accts").hide();

      $("#exams").fadeIn();
  });

    $("#create_exam").click(function(){
      $("#add_exams").hide();
      $("#exams").hide();
      $("#add_accts").hide();

      $("#add_exams").fadeIn();
  });

    $("#manage_accts").click(function(){
      $("#add_exams").hide();
      $("#exams").hide();
      $("#add_accts").hide();

      $("#add_accts").fadeIn();
  });

 //$(document).on("click", "#selectall",function(){ 
  $(document).on("submit","#submit_acct", function(){

       $("#add_accts").fadeIn();

  });

我的HTML是这样的

<div id="content">
 <input type="button" id="create_exam" value="Create Exam" title="Click to create new exam."  />
  <input type="button" id="view_exam" value="Exam" title="Click to view exam."  />
  <input type="button" id="manage_accts" value="Accounts" title="Click to view exam."  />
    <div id="add_accts">
       /*forms goes here */
    </div>

    <div id="add_exams">
       /*forms goes here */
    </div>

    <div id="exams">
       /*forms goes here */
    </div>
</div>

当我尝试提交数据时,div没有显示,我试图使用一个jquery来显示我想要的div但是它不起作用,所有这些都是隐藏的。我只需要保留显示当前显示的div,Any idea on this?

1 个答案:

答案 0 :(得分:0)

据我所知,即使在回复后之后,您仍希望保留可见div 。您可以使用隐藏字段来保留div可见性。请尝试以下代码段作为参考

$("#view_exam").click(function(){
      $("#add_exams").hide();
      $("#exams").hide();
      $("#add_accts").hide();

      $("#exams").fadeIn();
      $("#FiddenField_For_Current_Form").val("exams");
  });

在页面加载时检查 FiddenField_For_Current_Form 中的值,并显示相应的表格,如下所示

$(document).ready(function(){
  switch($("#FiddenField_For_Current_Form").val())
  {
    case "exams":
             $("#exams").fadeIn();
             break;

    default :
            $("#add_exams,#exams,#add_accts").hide();
             break;

  }


});
相关问题