示例工程 23-inputs

23-inputs/demo-02-numeric-date/index.html

html · 2.1 KB

运行:数字与日期输入演示

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

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>数字与日期输入演示</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; }
      label { display: block; margin: 8px 0 4px; font-size: 14px; }
      input { width: 100%; max-width: 320px; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }
      input[type="range"] { padding: 0; }
      input[type="color"] { width: 64px; height: 40px; padding: 2px; }
      code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, monospace; }
    </style>
  </head>
  <body>
    <h1>数字与日期</h1>

    <div class="box">
      <h2>数字与范围</h2>
      <label for="qty">数量(1–10,步长 1)</label>
      <input id="qty" name="qty" type="number" min="1" max="10" step="1" value="3" />
      <label for="score">评分(0–100,步长 10)</label>
      <input id="score" name="score" type="range" min="0" max="100" step="10" value="70" />
    </div>

    <div class="box">
      <h2>日期、时间与颜色</h2>
      <label for="day">日期</label>
      <input id="day" name="day" type="date" min="2026-01-01" max="2026-12-31" value="2026-11-28" />
      <label for="slot">时间</label>
      <input id="slot" name="slot" type="time" min="09:00" max="18:00" value="10:30" />
      <label for="tone">颜色</label>
      <input id="tone" name="tone" type="color" value="#2563eb" />
    </div>

    <div class="box">
      <h2>约束的作用</h2>
      <p><code>min</code> / <code>max</code> / <code>step</code> 让浏览器阻止明显越界,但仍要服务端校验。</p>
    </div>
  </body>
</html>