写一个web作业,登陆注册页面,实时显示时间
时间: 2024-03-10 19:45:46 浏览: 31
好的,这个任务比较简单。您可以按照以下步骤来实现:
1. 创建一个 HTML 文件,包含登陆注册表单和一个显示时间的区域。
```html
<!DOCTYPE html>
<html>
<head>
<title>登陆注册页面</title>
</head>
<body>
<h1>登陆</h1>
<form>
<!-- 表单内容 -->
</form>
<h1>注册</h1>
<form>
<!-- 表单内容 -->
</form>
<div id="time"></div>
</body>
</html>
```
2. 在 HTML 文件中添加 CSS 样式,可以设置表单的样式和时间区域的样式。
```css
form {
/* 表单样式 */
}
#time {
/* 时间区域样式 */
}
```
3. 在 HTML 文件中添加 JavaScript 代码,实现实时显示时间的功能。
```javascript
function updateTime() {
const now = new Date();
const timeEl = document.getElementById("time");
timeEl.innerText = now.toLocaleString();
}
setInterval(updateTime, 1000);
```
这样就完成了一个简单的登陆注册页面,并且实时显示当前时间。当用户打开网页时,页面会显示当前时间,每秒钟刷新一次。