如何使用bootbox.alert来停止执行该函数

时间:2016-01-30 01:07:06

标签: javascript java jquery twitter-bootstrap bootstrap-modal

我有这样的代码(在Javascript中):

<script>
    window.onload = function() {
        var http = getHTTPObject();
        if (http) {
            var anchors = document.getElementsByTagName("a");
            for (var foo = 0; foo < anchors.length; foo++) {
                if (anchors[foo].className == "httpauth") {
                    createForm(anchors[foo]);
                }
            }
        }
    }
    function createForm(jshttpauth) {
        var form = document.createElement("form");
        form.action = jshttpauth.href;
        form.method = "get";
        form.onsubmit = login;
        form.id = httpauth.id;
        var username = document.createElement("label");
        var usernameInput = document.createElement("input");
        usernameInput.name = "username";
        usernameInput.type = "text";
        usernameInput.id = httpauth.id + "-username";
        username.appendChild(document.createTextNode("Username:"));
        username.appendChild(usernameInput);
        var password = document.createElement("label");
        var passwordInput = document.createElement("input");
        passwordInput.name = "password";
        passwordInput.type = "password";
        passwordInput.id = httpauth.id + "-password";
        password.appendChild(document.createTextNode("Password:"));
        password.appendChild(passwordInput);
        var submit = document.createElement("input");
        submit.type = "submit";
        submit.value = "Log in";
        form.appendChild(username);
        form.appendChild(password);
        form.appendChild(submit);
        jshttpauth.parentNode.replaceChild(form, jshttpauth);
    }

    function login() {
        var username = document.getElementById(this.id + "-username").value;
        var password = document.getElementById(this.id + "-password").value;
        this.http.open("get", this.action, false, username, password);
        this.http.send("");
        if (http.status == 200) {
            document.location = this.action;
        } else {
            bootbox.alert("wrong username/password");
        }
        return false;
    }
</scritp>

我使用此代码通过html表单实现http身份验证。但问题是此代码在bootbox.alert ("Wrong username/password")页面login.html上显示login() {{1}函数只是继续执行,返回false(我在html中包含了bootstrap库)。但是当我使用alert()函数时它可以正常工作。我不知道如何解决这个问题。任何建议和建议将不胜感激。

0 个答案:

没有答案