<script type="text/javascript"> function validate(){ account = document.loginForm.account.value; password = documnet.loginForm.password.value; if(account==”“){ alert("账号"); documnet.loginForm.account.focus(); return; } else if(password==""){ alert("密码"); documnet.loginForm.password.focus(); return; } document.loginForm.submit(); } </script><form name="loginForm"> 用户名:<input name="account" type="text"><br> 密码:<input name="password" type="password"><br> 电话:<input type="tel"><br> 地址:<input type="text"><br> <input type="button" onclick="validate()" value="登录"> <a href = "历史订单.html">注册</a> <a href = "商品列表.html">返回</a> </form>这个转化成JavaScript语言
时间: 2023-06-19 15:05:58 浏览: 56
这段代码已经是 JavaScript 语言了,不需要再转化了。但是,代码中有一些错误:
1. `documnet` 应该是 `document`。
2. `alert("账号");` 和 `alert("密码");` 中的中文句号应该改成英文句号。
3. `<input type="button" onclick="validate()" value="登录">` 中的 `onclick` 应该改成 `onclick=""`,以免被浏览器拦截。
下面是修改后的代码:
```html
<script type="text/javascript">
function validate() {
account = document.loginForm.account.value;
password = document.loginForm.password.value;
if(account == "") {
alert("请输入账号。");
document.loginForm.account.focus();
return;
} else if(password == "") {
alert("请输入密码。");
document.loginForm.password.focus();
return;
}
document.loginForm.submit();
}
</script>
<form name="loginForm">
用户名:<input name="account" type="text"><br>
密码:<input name="password" type="password"><br>
电话:<input type="tel"><br>
地址:<input type="text"><br>
<input type="button" onclick="validate()" value="登录">
<a href="历史订单.html">注册</a>
<a href="商品列表.html">返回</a>
</form>
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<!DOCTYPE html> <html> <head> <title>登录界面</title> <meta charset="utf-8" /> <title></title> </head> <style> input[type="text"], input[type="password"] { display: block; width: 5%; padding: 10px; margin-bottom: 20px; border-radius: 5px; border: 1px solid #ccc; font-size: 1.2em; } body{ background: url(image/java.jpg) top left; width: 10240px; height: 5120px; background-attachment: fixed; background-repeat: no-repeat; background-size: 100%; } 00 input[type="submit"] { background-color: Transparent; color: #abc1ee; padding: 10px 20px; border-radius: 5px; border: none; font-size: 1.2em; cursor: pointer; } a { text-decoration-line: none; color: #abc1ee; } </style> <body> Welcome to Login Login <input type="text" name="username" placeholder="username" id="username"> <input type="password" name="password" placeholder="password" id="password"> <input type="submit" value="Login" onclick="validate()"> Don't have account? Sign up <script> // 定义全局变量 var usernameInput = document.getElementById("username"); var passwordInput = document.getElementById("password"); var errorCount = 0; function validate() { // 定义局部变量 var username = usernameInput.value; var password = passwordInput.value; // switch...case语句 switch (username) { case "": alert("用户名不能为空"); errorCount++; break; case "admin": if (password === "admin") { alert("登录成功"); } else { alert("密码错误"); errorCount++; } break; default: alert("用户名不存在"); errorCount++; break; } // for...in语句 for (var i in username) { if (username[i] === " ") { alert("用户名不能包含空格"); errorCount++; break; } } // if语句 if (password === "") { alert("密码不能为空"); errorCount++; } // 调用函数 displayError(); if (errorCount >= 3) { alert("错误次数过多,请稍后再试"); window.location.reload(); } } function displayError() { // 获取元素 var container = document.querySelector(".container"); // 创建元素节点 var errorDiv = document.createElement("div"); errorDiv.innerHTML = "输入有误,请重新输入"; errorDiv.style.color = "red"; // 对子节点的操作 container.appendChild(errorDiv); setTimeout(function() { container.removeChild(errorDiv); }, 3000); } </script> </body> </html>对这个界面进行优化,添加标签
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)