此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
表单
- 表单让人们能输入内容 —— 名字、留言、搜索词。
- 你打字的那些框,叫做输入框(input)。
- 文本框是
<input type="text">—— 单标签,和<img>一样。
标签和按钮
<label>是输入框旁边的文字,告诉用户这个框是干什么的。<button>是可以点的按钮 —— 比如 Send(发送)或 Search(搜索)。- 这里我们不会真的发送什么 —— 只是学这些标签。
English
<label for="name">Your name:</label>
<input type="text" id="name">
<button>Send</button>
常见错误
- 将每个标签与其对应的输入框链接:标签的
for与输入框的id匹配。点击文字时光标会定位到框内,屏幕阅读器也会朗读标签内容。 - 表单里的按钮默认会提交——用
type="button"阻止。
现在轮到你
- 输入框和按钮,是网上每一个表单的基本零件。
- 加一个文本框,再加一个按钮。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Add a box the user can type in. Use <input type="text"> (a single tag, like <img>).
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Add a button that says 发送. Use <button>Send</button>.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Add an email box with a label. Write <label for="email">Email:</label>, then <input type="email" id="email">. The for and the id must match.