HTML5“占位符”支持

HTML5“占位符”支持

问题描述:

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

How can I find out if the browser supports the HTML5 placeholder tag, so I can decide whether to hook my jQuery placeholder plugin or not.

var placeholderSupported = ( 'placeholder' in document.createElement('input') );

变量 placeholderSupported 将为 true ,如果它原生支持。否则,它将被设置为 false

The variable placeholderSupported will be true if it is natively supported. Otherwise, it'll be set to false.