猿问

为什么提交表单后,原窗口不会关闭?

                    <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">登录</button>
                    </div>
                </form>
                    </div>
        

<script type="text/javascript">
 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("登录失败");
            return false;
 }
    }
</script>


耂虍
浏览 2417回答 1
1回答

Caballarii

window.open和window.close都会有被浏览器拦截的可能性建议直接用window.location.href="TXL.html"代替window.open("TXL.html", '_blank');this.window.close();这两行
随时随地看视频慕课网APP
我要回答