diff --git a/files/zh-cn/web/html/attributes/step/index.md b/files/zh-cn/web/html/attributes/step/index.md new file mode 100644 index 00000000000000..1117ba001f8e70 --- /dev/null +++ b/files/zh-cn/web/html/attributes/step/index.md @@ -0,0 +1,138 @@ +--- +title: HTML 属性:step +slug: Web/HTML/Attributes/step +l10n: + sourceCommit: 067a40e4ed27ea6e1f3b8bbfec15cd9dc3078f4c +--- + +{{HTMLSidebar}} + +**`step`** 属性是值必须遵循的粒度数值,或关键字 `any`。此属性对数值输入类型有效,包括 {{HTMLElement("input/date", "date")}}、{{HTMLElement("input/month", "month")}}、{{HTMLElement("input/week", "week")}}、{{HTMLElement("input/time", "time")}}、{{HTMLElement("input/datetime-local", "datetime-local")}}、{{HTMLElement("input/number", "number")}} 和 {{HTMLElement("input/range", "range")}} 类型。 + +`step` 设置了点击上下旋转按钮、在范围上左右移动滑块以及验证不同日期类型时的*步进间隔*。如果没有明确指定,`number` 和 `range` 的 `step` 默认为 1,日期/时间输入类型的 `step` 默认为 1 个单位类型(分、周、月、日)。值必须是正数(整数或浮点数)或特殊值 `any`,这意味着不隐含步进,允许任何值(除其他限制外,如 [`min`](/zh-CN/docs/Web/HTML/Attributes/min) 和 [`max`](/zh-CN/docs/Web/HTML/Attributes/max))。 + +`number` 输入类型的默认步进值为 1,只允许输入整数,*除非*步进基数不是整数。`time` 的默认步进值为 60 秒,值 900 等同于 15 分钟。 + +## 语法 + +
输入类型 | +值 | +示例 | +
---|---|---|
{{HTMLElement("input/date", "date")}} | +1(天) | +<input type="date" min="2019-12-25" step="1"> |
+
{{HTMLElement("input/month", "month")}} | +1(个月) | +<input type="month" min="2019-12" step="12"> |
+
{{HTMLElement("input/week", "week")}} | +1(周) | +<input type="week" min="2019-W23" step="2"> |
+
{{HTMLElement("input/time", "time")}} | +60(秒) | +<input type="time" min="09:00" step="900"> |
+
+ {{HTMLElement("input/datetime-local", "datetime-local")}} + | +60(秒) | +
+ <input type="datetime-local" min="2019-12-25T19:30"
+ step="900">
+ |
+
{{HTMLElement("input/number", "number")}} | +1 | +
+ <input type="number" min="0" step="0.1" max="10">
+ |
+
{{HTMLElement("input/range", "range")}} | +1 | +<input type="range" min="0" step="2" max="10"> |
+