首页 > 解决方案 > 在 Firefox 中禁用 Javascript 时,HTML/Javascript 登录页面不考虑登录凭据

问题描述

我有一个简单的 html/js 登录脚本。当点击提交按钮提供正确的登录详细信息时,主页将打开。如果启用了 Javascript,这在 Google Chrome 和 Firefox 上运行良好。但是,当在 Firefox 中禁用 Javascript 时,不会考虑登录凭据,并且无论输入什么作为用户名或密码,都会在点击提交时打开主页。在禁用 Javascript 的情况下,有没有办法禁用提交按钮?我的脚本是:

<!doctype html>
<!-- This is is the main start page saved in index.html -->
<html lang="en-US">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>

<h2>Login details</h2>

<form 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>

标签: javascripthtml

解决方案


推荐阅读