所以我有一个html页面调用index.html,它看起来像:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<title>sometitle</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="Screen">
<section class="loginform cf">
<form action="#" method="post" id="loginwindow">
<ul>
<li>
<label for="usermail">Email</label>
<input type="email" name="useremail" placeholder="youremail@email.com" required>
</li>
<li>
<label for"password">Password</label>
<input type="password" name="password" placeholder="password" required>
</li>
<li>
<input type="submit" value="Check In">
</li>
</ul>
</form>
</section>
<script src="js/index.js"></script>
</div>
</body>
</html>
它有一个名为 index.js 的 js 文件,如下所示:
window.onload = function () {
var loginForm = document.getElementById('loginwindow');
if ( loginwindow ) {
loginwindow.onsubmit = function () {
var useremail = document.getElementById('useremail');
var password = document.getElementById('password');
// Make sure javascript found the nodes:
if (!useremail || !password ) {
load("LoopIt_DashBoard.html");
return "success";
}
}
}
}
function load(url)
{
$("#Screen").load(url, function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
test();
}
function test()
{
alert("test");
}
function test(string)
{
alert(string);
}
还有一个名为 LoopIt_DashBoard.html 的 html 文件,如下所示:
<div id="Screen">
<section class="loginform cf">
<form action="#" method="post" id="loginwindow">
<ul>
<li>
<input type="submit" value="Check In">
</li>
</ul>
</form>
</section>
</div>
现在这段代码所做的是获取电子邮件和密码,并将两者进行比较。如果它们相等,那么它会使用 LoopIt_DashBoard.html 文件中的代码更改 div 中的 html 和 id Screen。但是,如果我取出仅调用警报的线路(我将其用于测试)
test();
从
function load(url)
{
$("#Screen").load(url, function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
test();
}
那么这个功能不起作用,页面不会改变。如何在不使用警报的情况下更新我的视图。