示例工程 22-form-basics

22-form-basics/demo-02-post/index.html

html · 2.2 KB

运行:POST 表单演示

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>POST 表单演示</title>
    <style>
      body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
      .box { max-width: 720px; margin-bottom: 16px; padding: 18px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
      h1 { margin: 0 0 16px; font-size: 28px; }
      h2 { margin: 0 0 8px; font-size: 17px; }
      p { margin: 0 0 10px; color: #334155; }
      fieldset { margin: 0 0 12px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; }
      legend { padding: 0 6px; color: #475569; font-size: 13px; }
      label { display: block; margin-bottom: 4px; font-size: 14px; }
      input, textarea { width: 100%; max-width: 360px; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }
      textarea { min-height: 80px; }
      button { margin-top: 8px; padding: 7px 14px; border: 1px solid #2563eb; border-radius: 6px; background: #2563eb; color: #fff; font: inherit; }
      button[type="reset"] { margin-left: 8px; background: #fff; color: #334155; border-color: #cbd5e1; }
    </style>
  </head>
  <body>
    <h1>POST 表单</h1>

    <div class="box">
      <h2>反馈</h2>
      <form action="feedback.html" method="post">
        <fieldset>
          <legend>反馈信息</legend>
          <label for="name">称呼</label>
          <input id="name" name="name" type="text" autocomplete="name" />
          <label for="email">邮箱</label>
          <input id="email" name="email" type="email" autocomplete="email" />
          <label for="message">内容</label>
          <textarea id="message" name="message"></textarea>
        </fieldset>
        <button type="submit">发送</button>
        <button type="reset">清空</button>
      </form>
    </div>

    <div class="box">
      <h2>POST 的特点</h2>
      <p>数据在请求体里,不出现在 URL;但必须配合 HTTPS 才安全。</p>
      <p>提交后刷新页面可能重复提交,服务器需要做幂等或防重。</p>
    </div>
  </body>
</html>