javascript - 在 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>
解决方案
推荐阅读
- javascript - 在 javascript 中比较整数时遇到问题
- java - selenium 网格在同一浏览器上并行执行
- python - Python - 使用 scipy 加速余弦相似度
- google-cloud-platform - 你如何改变你的外部IP?
- r - fpc::dbscan 和 dbscan::dbscan 的结果不同
- xamarin.android - AssetManager 与内部存储:如何在 Xamarin Android 中存储我想稍后编辑的跨平台 config.json 文件?
- python - 使用 Perlin 噪声程序生成具有明显更高海拔的区域
- bash - 如何在 Vagrantfile 中使用动态值,例如 Shell 变量
- angularjs - 如何使用 ng-repeat 显示数组
- r - 如何遍历多个矩阵中的子集索引