隐藏表单并在表单提交上显示div

Mr.*_*. B 4 html javascript forms jquery

我正在尝试隐藏表单div id="first"并显示div id="second"按下提交按钮的时间.下面是我正在使用的代码,但它无法正常工作.结果是在页面返回其原始视图之前"快速"隐藏div id="first"和"快速"显示div id="second".

有人可以帮我纠正一下吗?谢谢!

$(document).ready(function() {
  $("#myform").submit(function(e) {
    $("#first").hide();
    $("#second").show();
  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>

<div id="first" class="1" style="display:">
  <form action="/student/webdesign/2015/4th/04_50/tinker/hideDiv/hide.php" method="post" id="myform">
    <p>

      <label for="textfield">Text Field:</label>
      <input type="text" name="name" id="name">
      <br>
      <input type=submit formmethod="POST">
    </p>
  </form>
</div>


<div id="second" class="2" style="display:none">
  test
</div>
Run Code Online (Sandbox Code Playgroud)

Hai*_*Ali 9

这可能是因为在提交表单时正在执行默认事件.试一试.

 $(document).ready(function() {
        $("#myform").submit(function(e) {
            e.preventDefault();
            $("#first").hide();
            $("#second").show();
        });
    });
Run Code Online (Sandbox Code Playgroud)

给这个读一读 - https://api.jquery.com/event.preventdefault/