input 常用类型
<input> 靠 type 属性变化出十几种控件,常用的有:text 单行文本、password 密码(掩码显示)、email 邮箱(手机上弹出带 @ 的键盘)、number 数字、date 日期选择器、checkbox 复选框、radio 单选框、file 文件选择、hidden 隐藏域。
几个高频细节:placeholder 是提示占位文字,不能代替 label;复选框和单选框要配 label 才好点击;同一组单选框必须共用相同的 name,浏览器才知道它们互斥;value 既决定默认值,也是提交时发送的内容。
本节要点type 决定控件形态与移动端键盘;radio 同组共用 name 才互斥;placeholder 只是提示不能替代 label;提交的值来自 value。
HTML
<form action="/api/apply" method="post"> <input type="text" name="nick" placeholder="请输入昵称"> <input type="email" name="mail" placeholder="邮箱"> <input type="number" name="age" min="1" max="120"> <input type="date" name="birthday"> <!-- 同一组单选框共用 name="gender",才能实现互斥 --> <label><input type="radio" name="gender" value="m"> 男</label> <label><input type="radio" name="gender" value="f"> 女</label> <!-- 复选框可以勾选多个,未勾选时不提交 --> <label><input type="checkbox" name="agree" value="yes"> 同意条款</label> <input type="file" name="avatar" accept="image/*"> <!-- 隐藏域:用户看不到,但会随表单一起提交 --> <input type="hidden" name="source" value="wiki-page"> <button type="submit">提交申请</button> </form>




