index.html:
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
input[type="text"], input[type="password"] {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
width: 250px;
font-size: 16px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
font-size: 16px;
margin-top: 20px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<form>
<h1>Login</h1>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<input type="submit" value="Login">
</form>
<script src="login.js"></script>
</body>
</html>
login.js:
const form = document.querySelector('form');
form.addEventListener('submit', function(event) {
event.preventDefault();
const username = form.elements['username'].value;
const password = form.elements['password'].value;
if (username === 'admin' && password === 'password') {
alert('Login Successful');
} else {
alert('Incorrect Username or Password');
}
});
参考chatGPT
放在同一个文件夹下
参考:
标签:username,web,第一个,form,type,input,password,border From: https://www.cnblogs.com/rebrobot/p/17223429.html