html css js做的在线签到例子

图片

代码

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>在线签到系统</title>

<style>

body {

font-family: Arial, sans-serif;

background-color: #f0f8ff;

padding: 20px;

}

.container {

background-color: white;

border-radius: 10px;

box-shadow: 0 0 10px rgba(0,0,0,0.1);

padding: 20px;

width: 300px;

margin: auto;

text-align: center; /* 居中内容 */

}

inputtype=text, inputtype=email {

width: 100%;

padding: 10px;

margin: 5px 0 15px 0;

border: 1px solid #b3b3b3;

border-radius: 5px;

box-sizing: border-box;

}

button {

background-color: #4d90fe; /* 蓝色背景 */

color: white;

padding: 10px 25px; /* 调整宽度 */

border: none;

border-radius: 5px;

cursor: pointer;

}

button:hover {

background-color: #4787ed; /* 鼠标悬停时的蓝色 */

}

.alert {

color: red;

display: none;

}

table {

width: 100%;

margin-top: 20px;

border-collapse: collapse;

}

th, td {

border: 1px solid #ddd;

padding: 8px;

text-align: left;

border-radius: 5px;

}

th {

background-color: #4d90fe; /* 蓝色背景 */

color: white;

}

tr:nth-child(even) {

background-color: #f2f2f2;

}

</style>

<script>

function checkIn() {

var name = document.getElementById("name").value.trim(); // 去除前后空格

var email = document.getElementById("email").value.trim();

var alert = document.getElementById("alert");

var checkInList = document.getElementById("checkInList");

if (name === "" || email === "") {

alert.textContent = "姓名和邮箱不能为空!";

alert.style.display = "block";

return;

} else if (localStorage.getItem(email + "_checked")) { // 使用_email_checked避免冲突

alert.textContent = "您已签到过!";

alert.style.display = "block";

return;

} else {

localStorage.setItem(email + "_checked", "true");

alert.textContent = "签到成功!";

alert.style.display = "block";

// 添加签到记录到表格

var newRow = checkInList.insertRow(-1);

var nameCell = newRow.insertCell(0);

var emailCell = newRow.insertCell(1);

nameCell.textContent = name;

emailCell.textContent = email;

// 清空输入框

document.getElementById("name").value = "";

document.getElementById("email").value = "";

setTimeout(function() {

alert.style.display = "none";

}, 2000);

}

}

</script>

</head>

<body>

<div class="container">

<h2>在线签到</h2>

<input type="text" id="name" placeholder="姓名" required>

<input type="email" id="email" placeholder="邮箱" required>

<button οnclick="checkIn()">签到</button>

<p id="alert" class="alert"></p>

<h3>签到记录</h3>

<table>

<thead>

<tr>

<th>姓名</th>

<th>邮箱</th>

</tr>

</thead>

<tbody id="checkInList">

<!-- 签到记录将动态插入此处 -->

</tbody>

</table>

</div>

</body>

</html>

相关推荐
大家的林语冰2 小时前
✌️ Deno 2.9 来了,ESM 直接导入 CSS,甚至能开发桌面应用?!
前端·javascript·node.js
不简说3 小时前
JS 代码技巧 vol.1 — 10 个让代码少写 30% 的小套路
前端·javascript·面试
@@@@@@@@543 小时前
JavaScript 的缺点与 TypeScript 的弥补
开发语言·javascript·typescript
Hilaku3 小时前
为什么业务型前端容易遭遇中年危机?
前端·javascript·程序员
এ慕ོ冬℘゜3 小时前
深度解析 JavaScript:赋予 Web 灵魂的“全栈语言”
开发语言·前端·javascript
梨想橙汁3 小时前
吃透HTML5:从基础标签到核心新特性全覆盖
html
铁皮饭盒4 小时前
Bun 处理 IO 密集型比 Java 强多少?
javascript
anod4 小时前
Amazon反爬虫:一场从自动化到Chrome插件的折腾之旅
javascript·chrome·amazon·插件
石像鬼₧魂石5 小时前
【Y2Ksoft】贵阳陈桥饭店ERP管理系统
大数据·前端·物联网·html·数据库架构
TheITSea5 小时前
4、React+Tailwind CSS
前端·css·react.js