检测输入类型="日期"是否支持占位符

Dio*_*oso 5 html javascript jquery html5 modernizr

是否可以检测浏览器是否支持input type="date"placeholder

dav*_*010 7

W3验证器表示占位符属性在日期输入中无效.验证此HTML:

<!doctype html>
<title>date placeholder test</title>
<input type="date"  placeholder="enter a date">
Run Code Online (Sandbox Code Playgroud)

给出错误:" Attribute placeholder not allowed on element input at this point."......并说你可以使用属性" placeholder when type is text, search, url, tel, e-mail, password, or number".

此外,Chrome不会显示日期输入的占位符,即使它认为JS中存在该属性(这大致是Modernizr检查属性的方式):

var test = document.createElement(element);
test.type = 'date';
alert('placeholder' in test);
Run Code Online (Sandbox Code Playgroud)