修改代码<script> function generateRequest() { var username = document.getElementById("username").value; var password = document.getElementById("password").value; var flag = false; if (username==="yh" && password="321") { window.location.href = "update"; // 成功跳转到success.html } else { window.location.href = "404"; // 失败跳转到error.html } } </script>
时间: 2024-01-19 19:02:47 浏览: 115
在这段代码中,有一个语法错误。在比较`password`的值时,应该使用双等号`==`,而不是单等号`=`。正确的代码如下:
```
<script>
function generateRequest() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var flag = false;
if (username==="yh" && password=="321") {
window.location.href = "update"; // 成功跳转到success.html
} else {
window.location.href = "404"; // 失败跳转到error.html
}
}
</script>
```
这样修改后,当`password`的值为`321`时,才会跳转到`success.html`页面。
相关问题
为下列html页面添加css样式表<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>User Login Form</title> </head> <body> <h1>User Login</h1> <form onsubmit="generateRequest(); return false;" > <label>Username:</label> <input type="text" id="username" name="username" /><br /><br /> <label>Password:</label> <input type="password" id="password" name="password" /><br /><br /> <input type="submit" value="Submit" /> </form> <script> function generateRequest() { var username = document.getElementById("username").value; var password = document.getElementById("password").value; var url = "http://localhost:8080/login?username=" + username + "&password=" + password; var request = new XMLHttpRequest(); request.open("GET", url); request.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { window.location.href = "query"; // 成功跳转到success.html } else { window.location.href = "404"; // 失败跳转到error.html } }; request.send(); } </script> </body> </html>
以下是一个示例的CSS样式表,你可以将其添加到HTML文件的<head>标签内:
```css
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
margin: 0;
padding: 0;
}
h1 {
font-size: 32px;
font-weight: bold;
color: #444;
text-align: center;
margin-top: 50px;
}
form {
width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 30px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
label {
display: block;
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
border: 2px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin-bottom: 20px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
```
这个样式表会将页面的背景设置为浅灰色,标题设置为黑色粗体居中显示,表单部分设置为白色背景,有阴影效果,并且添加了一些基本的表单样式。你可以根据自己的需要修改这个样式表。
阅读全文