首先,我对此很陌生,我真的尽力了解它是如何工作的。我有以下简单的登录表单,如果提交正确的登录凭据,该表单将进入主页。然而,当在禁用 JavaScript 的 Firefox 中运行时,登录凭据将被忽略,并且无论我提供什么登录详细信息,我的主页都会显示。我创建了一条消息,<noscript></noscript>当 JavaScript 被禁用时会在该消息之间触发。我想要实现的是,仅显示警告消息,并且表单等被禁用,并且在启用 JavaScript 的情况下重新加载登录页面之前不会显示。有人可以帮我解决这个问题吗?非常感谢!我的代码是
<!doctype html>
<!-- This is is the main start page saved in index.html -->
<html>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<h2>Login details</h2>
<noscript>
<h3>Before you login</h3>
<p>JavaScript needs to run for this site to work properly.<br />
Please activate JavaScript in your browser<br />
and reload this page to login.
</p>
</noscript>
<form id="myForm" name="login" onsubmit="return validateFormOnSubmit()" action="http://localhost:8080/index.html" method="post">
<fieldset>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
</body>
</html>
<script>
function validateFormOnSubmit() {
var un = document.login.username.value;
var pw = document.login.password.value;
var username = "username"
var password = "password"
if ((un == username) && (pw == password)) {
return true;
}
else {
alert ("Login was unsuccessful, please check your username and password");
return false;
}
}
</script>
慕尼黑5688855
相关分类