我是 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("assword 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="[email protected]" placeholder="Username" class="middle textfield"/>
</div>
<div data-role="fieldcontain" >
<input type="password" name="password" id="password" value="789456" placeholder="assword" class="middle textfield" maxlength="10"/>
</div>
<div class = "middle">
<button id = "BtnClick" class = "button" >Submit</button>
</div>
</form>
</body>
</html>
Best Answer-推荐答案 strong>
感谢大家的帮助!我找到了解决方案:
在index.html
<div class = "loginButton">
<a id = "BtnClick">Submit</a>
</div>
在validateform 方法中:
window.location.href = "home.html";
关于ios - 在 Cordova 中使用 Button 进行登录验证后重定向,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/52420959/
|