在 Cordova 中使用 Button 进行登录验证后重定向

Redirect after Login validation using Button in Cordova

我是科尔多瓦语言的初学者。我试图在 javascript 中点击按钮时重定向我的 html 页面。在 validateform 方法中,我想重定向到我的主页。我已经尝试了所有可能的事情,例如 window.location, document.location 。但我没有得到重定向的确切答案。

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        window.onload = function()
        {
            document.addEventListener("deviceready", init, false);
        }

    function init()
    {
        var myButton = document.getElementById("BtnClick");
        myButton.addEventListener("click", validateform, false);
    }

    function validateform()
    {
        var myButton = document.getElementById("BtnClick");
        var user = document.getElementById("username").value;
        var paswd = document.getElementById("password").value;
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if (user == "") {
            alert("Name must be filled out");
            return false;
        } else if (reg.test(user) == false) {
            alert("Invalid Email Address");
            return false;
        } else  if (paswd == "") {
            alert("Password must be filled out");
            return false;
        } else {
            alert("TRY!");
            document.location = "home.html";
            return false;
        }
    }
        </script>

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
        <meta name="format-detection" content="telephone=no">
            <meta name="msapplication-tap-highlight" content="no">
                <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
                    <link rel="stylesheet" type="text/css" href="css/index.css">
                        </head>

<body>
    <form id="loginForm" class = "centered" >
        <div class="middle">
            <img src = "img/newlogo.png" width="150" height="150"/>
        </div>

        <div data-role="fieldcontain">
            <input type="email" name="username" id="username" value="tst@test.com" placeholder="Username" class="middle textfield"/>
        </div>

        <div data-role="fieldcontain" >
            <input type="password" name="password" id="password" value="789456" placeholder="Password" class="middle textfield" maxlength="10"/>
        </div>

        <div class = "middle">
            <button id = "BtnClick" class = "button" >Submit</button>
        </div>
    </form>
</body>
</html>

感谢大家的帮助!我找到了解决方案:

index.html

<div class = "loginButton">
      <a id = "BtnClick">Submit</a>
</div>

validateform方法中:

window.location.href = "home.html";