给定 HTML 文档
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<form>
<input type="email" placeholder="E-Mail"/>
</form>
</body>
</html>
W3C validator (v1.3) 给出以下错误信息:
Line 8, Column 48: Attribute
placeholder
is only allowed when the input type is e-mail, number, password, search, tel, text, or url.
为什么?
最佳答案
这似乎是验证器中的错误。
两个验证器,http://validator.w3.org/和 http://validator.w3.org/nu/ , 报告 placeholder
属性“仅当输入类型为 e-mail
[…] 时才允许”。
但是,HTML5 输入类型称为 email
,而不是 e-mail
(如果使用 type="e-mail"
,两个验证器都能正确识别)。
不看代码,我猜当使用 placeholder
时,他们会检查 e-mail
而不是 email
。它与所有其他允许的输入类型一起按预期工作。
关于html - W3C 验证器错误 : Attribute placeholder is only allowed when the input type is,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333088/