示例工程 23-inputs

23-inputs/demo-01-text-family/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: 360px; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }
      code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, monospace; }
      pre { margin: 8px 0 0; padding: 10px; overflow-x: auto; border-radius: 8px; background: #0f172a; color: #e2e8f0; font-size: 12px; }
    </style>
  </head>
  <body>
    <h1>文本类输入</h1>

    <div class="box">
      <h2>五种类型</h2>
      <label for="email">邮箱 type="email"</label>
      <input id="email" name="email" type="email" autocomplete="email" />
      <label for="phone">电话 type="tel"</label>
      <input id="phone" name="phone" type="tel" autocomplete="tel" inputmode="tel" />
      <label for="site">网址 type="url"</label>
      <input id="site" name="site" type="url" inputmode="url" />
      <label for="q">搜索 type="search"</label>
      <input id="q" name="q" type="search" />
      <label for="pwd">密码 type="password"</label>
      <input id="pwd" name="pwd" type="password" autocomplete="current-password" />
    </div>

    <div class="box">
      <h2>区别在哪</h2>
      <pre>email → 带 @ 的键盘 + 格式提示
tel   → 电话键盘(不做严格校验)
url   → 带 / 的键盘 + 协议提示
search→ 搜索键盘,部分浏览器带清除按钮
password → 隐藏输入</pre>
      <p>类型影响体验,不替代服务端校验。</p>
    </div>
  </body>
</html>