我刚刚检查了 HTML5 规范中类型为数字的输入,它明确表示占位符 不得使用属性。当我尝试使用输入类型验证 html 时,我也遇到 http://validator.w3.org 错误带有占位符属性的数字。看起来浏览器可能支持这一点,但它在 HTML5 规范中无效。
I've just checked against the HTML5 spec for input where a type is number and it explicitly says that the placeholder attribute may not be used. I also had errors with http://validator.w3.org when I tried to validate html with an input type of number with a placeholder attribute. Looks like browsers may support this but it's not valid in the HTML5 spec.
The following common input element content attributes apply to the element: autocomplete, list, max, min, placeholder, readonly, required, and step content attributes;
Sometimes it's helpful to offer an in-context hint as to what form the input data should take. This can be especially important if the page design doesn't offer descriptive labels for each <input>. This is where placeholders come in. A placeholder is a value that demonstrates the for the value should take by presenting an example of a valid value, which is displayed inside the edit box when the element's value is "". Once data is entered into the box, the placeholder disappears; if the box is emptied, the placeholder reappears.
发布评论
评论(4)
我刚刚检查了 HTML5 规范中类型为数字的输入,它明确表示占位符 不得使用属性。当我尝试使用输入类型验证 html 时,我也遇到 http://validator.w3.org 错误带有占位符属性的数字。看起来浏览器可能支持这一点,但它在 HTML5 规范中无效。
I've just checked against the HTML5 spec for input where a type is number and it explicitly says that the placeholder attribute may not be used. I also had errors with http://validator.w3.org when I tried to validate html with an input type of number with a placeholder attribute. Looks like browsers may support this but it's not valid in the HTML5 spec.
@zachleat 是正确的,最新的 HTML5 规范中允许使用
placeholder
属性:HTML 5.1 第二版:表单、number-state-typenumber(请参阅簿记部分)
@zachleat is correct, the
placeholder
attribute is allowed in the latest HTML5 spec:HTML 5.1 2nd Edition: forms, number-state-typenumber (see the bookkeeping section)
以下是 MDN Web 文档中关于
的占位符部分:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Placeholders
Here is the Placeholders section in the MDN Web Docs about
<input type="number">
: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Placeholders使用占位符:
使用最小值和最大值:
< input type="number" placeholder="10">
使用值:
Using Placeholder:
<input type="number" placeholder="10">
Using Min and Max Values:
<input type="number" placeholder="10">
Using Value:
<input type="number" value="10">