一、实训考核要求: 1、制作一个登录界面,输入用户名(自己名字)和密码(12345),并且进行验证,当验证成功则提示登录成功跳转到指定页面(自己设定),当不成功时提示用户名或密码错误,请重新登录,返回当前页。并且用两个命令按钮,一个实现‘提交’的功能,另一个实现“重置”的功能(文本框内容清空)。 2、跳转到的指定页面(要求:跳转到留言板,留言板能 实现发布留言,删除留言功能。) 3、跳转到的指定页面中的图片能实现动态效果(如随机 显示图片或图片变换大小或广告轮播) 4、页面设计美观,结构完整。这道题用js代码写出来
时间: 2024-03-22 11:36:52 浏览: 18
好的,以下是一个简单的实现:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h2>登录</h2>
<form id="login-form">
<label>用户名:</label>
<input type="text" id="username" name="username"><br>
<label>密码:</label>
<input type="password" id="password" name="password"><br>
<button type="submit">提交</button>
<button type="reset">重置</button>
</form>
</div>
<script src="jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>
```
CSS代码:
```css
body {
font-family: Arial, sans-serif;
}
.container {
width: 400px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
text-align: center;
}
h2 {
margin-top: 0;
}
label {
display: inline-block;
width: 80px;
text-align: right;
margin-right: 10px;
}
input[type=text],
input[type=password] {
width: 200px;
padding: 5px;
margin-bottom: 10px;
border-radius: 3px;
border: 1px solid #ccc;
}
button[type=submit],
button[type=reset] {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
margin: 10px;
border-radius: 5px;
cursor: pointer;
}
button[type=submit]:hover,
button[type=reset]:hover {
background-color: #3e8e41;
}
```
JavaScript代码:
```js
$(document).ready(function() {
// 点击提交按钮时
$('#login-form').submit(function(event) {
event.preventDefault(); // 阻止表单提交
var username = $('#username').val();
var password = $('#password').val();
if (username === 'YourName' && password === '12345') {
alert('登录成功!');
window.location.href = '留言板.html'; // 跳转到留言板页面
} else {
alert('用户名或密码错误,请重新输入!');
$('#username').val(''); // 清空用户名
$('#password').val(''); // 清空密码
$('#username').focus(); // 让用户名输入框获得焦点
}
});
// 点击重置按钮时
$('#login-form').on('reset', function(event) {
event.preventDefault(); // 阻止表单重置
$('#username').val(''); // 清空用户名
$('#password').val(''); // 清空密码
$('#username').focus(); // 让用户名输入框获得焦点
});
});
```
此代码实现了一个登录界面,并且输入用户名和密码后进行验证,验证成功则跳转到留言板页面,验证失败则提示用户名或密码错误,同时提供提交和重置按钮。留言板页面中的图片可以通过其他库实现动态效果。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)