【问题标题】:Why the original window doesn't close after submit?为什么提交后原始窗口没有关闭?
【发布时间】:2016-12-27 10:05:57
【问题描述】:

function login() {
  var un = document.getElementById("username").value;
  var pw = document.getElementById("password").value;
  if (un == "admin" && pw == "admin") {
    window.open("TXL.html", '_blank');
    this.window.close();
    return true;
  }
  else {
    alert("FAIL");
    return false;
  }
}
<div class="modal-body">
  <form action="" class="form center-block" onsubmit="login()">
    <div class="form-group">
      <input type="text" id="username" class="form-control input-lg" placeholder="">
    </div>
    <div class="form-group">
      <input type="password" id="password" class="form-control input-lg" placeholder="">
    </div>
    <div class="form-group">
      <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
    </div>
  </form>
</div>

登录窗口在提交后刷新。 我尝试了"window.open("TXL.html", '_self');",但它不起作用,甚至无法打开新窗口。 我也试过 window.location.href=""; ,它仍然不起作用。 感谢阅读!

【问题讨论】:

标签: javascript html twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

Working fiddle.

您必须在onsubmit 事件中添加返回:

<form action="" class="form center-block" onsubmit="return login()">

希望这会有所帮助。

【讨论】:

  • 你想达到什么目的?你在我的回答中试过沃特金小提琴吗?是你想要的吗?
  • sry,我想打开一个新窗口,然后在提交后关闭登录窗口,而不仅仅是提醒。
【解决方案2】:

&lt;form action="" class="form center-block" onsubmit="login()"&gt;

也许我应该使用“onclick”而不是“onsubmit”?

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2017-06-21
    • 2011-09-26
    • 2012-08-14
    • 1970-01-01
    • 2014-08-22
    • 2021-01-16
    • 2018-03-05
    • 1970-01-01
    相关资源
    最近更新 更多