Web前端 html+js+css 一个简单的在线签到

页面长这样- 

例图

 

 以下是代码部分:

<!DOCTYPE html>
<html>
  <head>
    <title>签到页面</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
        margin: 0;
        padding: 20px;
      }
      
      .container {
        max-width: 600px;
        margin: 0 auto;
        background-color: #fff;
        border-radius: 10px;
        padding: 20px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      }
      
      h1 {
        text-align: center;
        color: #333;
      }
      
      .form-container {
        margin-bottom: 20px;
      }
      
      .form-container label {
        display: block;
        margin-bottom: 10px;
        font-weight: 600;
      }
      
      .form-container input[type="text"],
      .form-container button {
        width: 100%;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 4px;
      }
      
      .form-container button[type="submit"] {
        margin-top: 10px;
        background-color: #4caf50;
        color: #fff;
        border: none;
        border-radius: 4px;
        cursor: pointer;
      }
      
      .form-container button[type="submit"]:hover {
        background-color: #45a049;
      }
      
      .signed-users {
        border-top: 1px solid #ccc;
        padding-top: 20px;
      }
      
      .signed-users h2 {
        font-size: 18px;
        margin-bottom: 10px;
        color: #333;
      }
      
      .signed-users ul {
        list-style-type: none;
        padding: 0;
        margin: 0;
      }
      
      .signed-users li {
        margin-bottom: 5px;
      }
      
      .signed-users li span {
        color: #555;
      }
      
      .success-message {
        color: green;
        text-align: center;
        margin-top: 10px;
      }
      
      .error-message {
        color: red;
        text-align: center;
        margin-top: 10px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>签到</h1>
      
      <div class="form-container">
        <form id="sign-in-form">
          <label for="name">姓名:</label>
          <input type="text" id="name" name="name" placeholder="请输入姓名">
          
          <label for="email">邮箱:</label>
          <input type="text" id="email" name="email" placeholder="请输入邮箱">
          
          <button type="submit">签到</button>
        </form>
      </div>
      
      <div class="signed-users">
        <h2>已签到用户:</h2>
        <ul id="user-list"></ul>
      </div>
      
      <div id="success-message" class="success-message"></div>
      <div id="error-message" class="error-message"></div>
    </div>
    
    <script>
      // 获取表单元素和用户列表元素
      const form = document.getElementById('sign-in-form');
      const userList = document.getElementById('user-list');
      const successMessage = document.getElementById('success-message');
      const errorMessage = document.getElementById('error-message');
      const signedUsers = []; // 已签到用户数组
      
      // 监听表单提交事件
      form.addEventListener('submit', function(e) {
        e.preventDefault();
        
        // 获取姓名和邮箱输入框的值
        const name = document.getElementById('name').value;
        const email = document.getElementById('email').value;
        
        if (name && email) {
          if (signedUsers.includes(email)) {
            errorMessage.textContent = '该邮箱已签到过!';
            successMessage.textContent = '';
          } else {
            // 创建新的列表项
            const listItem = document.createElement('li');
            listItem.innerHTML = `<strong>${name}</strong> - <span>${email}</span>`;
            
            // 将列表项添加到用户列表中
            userList.appendChild(listItem);
            
            // 添加邮箱到已签到用户数组中
            signedUsers.push(email);
            
            // 清空输入框的值
            document.getElementById('name').value = '';
            document.getElementById('email').value = '';
            successMessage.textContent = '签到成功!';
            errorMessage.textContent = '';
          }
        } else {
          errorMessage.textContent = '请填写姓名和邮箱!';
          successMessage.textContent = '';
        }
      });
    </script>
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值