HTML5"占位符"支持

Ale*_*lex 14 javascript jquery html5 placeholder

如何确定浏览器是否支持HTML5占位符标记,以便我可以决定是否挂钩我的jQuery占位符插件.

Jos*_*ber 17

var placeholderSupported = ( 'placeholder' in document.createElement('input') );
Run Code Online (Sandbox Code Playgroud)

该变量placeholderSupportedtrue是本机支持的.否则,它将被设置为false.


thi*_*dot 16

http://diveinto.html5doctor.com/everything.html#placeholder

return 'placeholder' in document.createElement('input');
Run Code Online (Sandbox Code Playgroud)

但是,你正在使用的jQuery插件可能已经检查本机支持-你可能并不需要这个做自己.