freeCodeCamp/guide/chinese/certifications/responsive-web-design/basic-html-and-html5/use-html5-to-require-a-field/index.md

15 lines
959 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Use HTML5 to Require a Field
localeTitle: 使用HTML5需要字段
---
## 使用HTML5需要字段
`required`属性适用于几乎所有可能类型的`input`标记(它不起作用,因为它对类似按钮的类型或具有默认值的`type=range`没有意义,例如`type=range` 并强制用户离开提交_时至少_与所需输入交互的最小标记选择_至少_一个复选框 _在_文本框中键入_至少_一个字符等
它的使用阻止了表单提交,直到`required`条件没有被填满
您可以使用特定语法的`required`属性:因为它是一个布尔值,您可能只`required`编写而没有任何值。
在这个挑战中,你已经有了一个表单和一个输入元素:它要求你将`required`属性添加到input元素;请记住,如果原始代码的某些内容被意外修改或删除,您可以使用`reset all code`按钮始终使用干净的代码重新启动。
祝你好运!