美文网首页
实现一个简单的登录界面,以表单数据格式传递参数

实现一个简单的登录界面,以表单数据格式传递参数

作者: 祈澈菇凉 | 来源:发表于2023-09-25 09:28 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录界面</title>
  <style>
    body {
      background-color: #f2f2f2;
      font-family: Arial, sans-serif;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100vh;
    }
    
    .login-container {
      background-color: #FFF;
      border-radius: 10px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
      padding: 30px;
      width: 300px;
    }
    
    .login-container h2 {
      color: #333;
      font-size: 24px;
      margin-bottom: 20px;
      text-align: center;
    }
    
    .login-form {
      margin-bottom: 20px;
    }
    
    .login-form label {
      display: block;
      color: #555;
      font-size: 16px;
      margin-bottom: 10px;
    }
    
    .login-form input[type="text"],
    .login-form input[type="password"] {
      width: 100%;
      padding: 10px;
      border: 1px solid #DDD;
      border-radius: 4px;
      outline: none;
    }
    
    .login-button {
      background-color: #E25822;
      color: #FFF;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      padding: 10px 20px;
      font-size: 16px;
      transition: background-color 0.3s ease;
      width: 100%;
    }
    
    .login-button:hover {
      background-color: #BF4316;
    }
  </style>
</head>
<body>
  <div class="login-container">
    <h2>登录</h2>
    <form class="login-form">
      <label for="username">用户名</label>
      <input type="text" id="username" placeholder="请输入用户名">
      <label for="password">密码</label>
      <input type="password" id="password" placeholder="请输入密码">
    </form>
    <button class="login-button">登录</button>
  </div>
</body>
</html>

发送请求,以表单数据(application/x-www-form-urlencoded)格式:传递参数

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录界面</title>
  <style>
    body {
      background-color: #f2f2f2;
      font-family: Arial, sans-serif;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100vh;
    }
    
    .login-container {
      background-color: #FFF;
      border-radius: 10px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
      padding: 30px;
      width: 300px;
    }
    
    .login-container h2 {
      color: #333;
      font-size: 24px;
      margin-bottom: 20px;
      text-align: center;
    }
    
    .login-form {
      margin-bottom: 20px;
    }
    
    .login-form label {
      display: block;
      color: #555;
      font-size: 16px;
      margin-bottom: 10px;
    }
    
    .login-form input[type="text"],
    .login-form input[type="password"] {
      width: 100%;
      padding: 10px;
      border: 1px solid #DDD;
      border-radius: 4px;
      outline: none;
    }
    
    .login-button {
      background-color: #E25822;
      color: #FFF;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      padding: 10px 20px;
      font-size: 16px;
      transition: background-color 0.3s ease;
      width: 100%;
    }
    
    .login-button:hover {
      background-color: #BF4316;
    }
  </style>
  <script>
    function loginUser() {
      const username = document.getElementById('username').value;
      const password = document.getElementById('password').value;

      const formData = new URLSearchParams();
      formData.append('username', username);
      formData.append('password', password);

      fetch('https://example.com/login', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: formData
      })
        .then(response => response.json())
        .then(data => {
          // 处理响应数据
          console.log(data);
        })
        .catch(error => {
          // 处理错误
          console.error(error);
        });
    }
  </script>
</head>
<body>
  <div class="login-container">
    <h2>登录</h2>
    <form class="login-form">
      <label for="username">用户名</label>
      <input type="text" id="username" placeholder="请输入用户名">
      <label for="password">密码</label>
      <input type="password" id="password" placeholder="请输入密码">
    </form>
    <button class="login-button" onclick="loginUser()">登录</button>
  </div>
</body>
</html>

添加了一个 JavaScript 函数 loginUser(),该函数在用户点击登录按钮时触发。函数中,获取用户名和密码的值,创建表单数据对象,并使用 Fetch API 发送 POST 请求。

相关文章

  • 智慧商超系统

    智能商超登录 1.登录界面 2. 登录界面实现的功能描述 实现不同用户类型登陆。 3.登录界面各控件的参数设置 控...

  • 2018-10-21

    智能商超登录 1.登录界面 2. 登录界面实现的功能描述 实现不同用户类型登陆。 3.登录界面各控件的参数设置 控...

  • 2018-09-26

    智能商超登录 1.登录界面 2. 登录界面实现的功能描述 实现不同用户类型登陆情况。 3.登录界面各控件的参数设置...

  • 2018-10-20

    1. 登录界面的效果图 2. 登录界面实现的功能描述 实现不同的身份登陆 3. 登录界面各控件的参数设置 控件A ...

  • 2018-10-21

    1.登录界面的效果图 2. 登录界面实现的功能描述 实现不同用户类型登陆 3. 登录界面各控件的参数设置 控件A ...

  • 2018-10-21

    一、登录界面设计 二、登录界面实现功能 三、登录界面各控件的参数设置 控件1 控件2 控件4 四、重要方法描述 角...

  • 2018-10-21

    一、登录界面设计 二、登录界面实现功能 三、登录界面各控件的参数设置 控件1 控件2 控件4 四、重要方法描述 角...

  • 商超系统登陆界面 廖世豪

    一、登录界面设计 二、登录界面实现功能 三、登录界面各控件的参数设置 控件1 控件2 控件4 四、重要方法描述 角...

  • the QuickDialog class layout ana

    QuickDialog可以帮助开发者快速创建复杂的表单,实现包括登录界面在内的各种样式的TableView输入界面...

  • 杨鑫

    1. 登录界面的效果图: 2. 登录界面实现的功能描述 3. 登录界面各控件的参数设置 控件A 控件B 控件C 4...

网友评论

      本文标题:实现一个简单的登录界面,以表单数据格式传递参数

      本文链接:https://www.haomeiwen.com/subject/fcafbdtx.html