停止弹出登录表单以刷新页面

时间:2016-12-14 10:05:03

标签: javascript php jquery html

尝试从刷新中停止此登录表单我使用了此表单的w3schools指南。 http://www.w3schools.com/howto/howto_css_login_form.asp。这是"模式"示例

这是模态代码:

<div id="id01" class="modal">
<span onclick="document.getElementById('id01').style.display='none'" 
class="close" title="Close Modal">&times;</span>

<!-- Modal Content -->
<form class="modal-content animate">
 <label for="my-checkbox">Checkbox</label>

  <div class="container">
    <label><b>Username</b></label>
    <input type="text" placeholder="Enter Username" name="uname" required>
  <br>
  <label><b>Password</b></label>
  <input type="password" placeholder="Enter Password" name="psw" required>
<br>
  <button type="submit">Login</button>
  <input type="checkbox" checked="checked"> Remember me
</div>

<div class="container" style="background-color:#f1f1f1">

  </div>
 </form>
</div>

 <!-- Js part -->
       function stopDefAction(evt) {
    evt.preventDefault();
 }
 document.getElementById('my-checkbox').addEventListener( 'click',    stopDefAction, false );

 <!-- Button to open the modal login form -->
<button id="button1" onclick="document.getElementById('id01').style.display='block'" action="login.php">Login</button>

1 个答案:

答案 0 :(得分:0)

使用AJAX提交for ..这将允许您发布表单获取,获取响应并根据需要更新UI而无需刷新页面...

var xhttp = new XMLHttpRequest();

http.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      // get response here and perform any UI actions
    }
  };
  xhttp.open("method", "filename", true);
  xhttp.send();
相关问题