--- id: bad87fee1348bd9aedc08830 title: Use HTML5 to Require a Field challengeType: 0 videoUrl: 'https://scrimba.com/p/pVMPUv/cMd4EcQ' forumTopicId: 18360 localeTitle: 给表单添加一个必填字段 --- ## Description
当你设计表单时,你可以指定某些字段为必填项(required),只有当用户填写了该字段后,才可以提交表单。 如果你想把文本输入框设置为必填项,在input元素中加上 required 属性就可以了,例如:<input type="text" required>
## Instructions
input元素加上required属性,这样用户就必须先在输入框里填入内容,然后才可以提交表单。
## Tests
```yml tests: - text: 'input元素必须有required属性。' testString: assert($("input").prop("required")); ```
## Challenge Seed
```html

CatPhotoApp

点击查看更多猫咪图片

一只仰卧着的萌猫

猫咪最喜欢的三件东西:

  • 猫薄荷
  • 激光笔
  • 千层饼

猫咪最讨厌的三件东西:

  1. 跳蚤
  2. 打雷
  3. 同类
```
## Solution