如果用户的浏览器支持的话,我想在代码中使用HTML5
"placeholder"
属性,否则只需在表单顶部打印字段名即可。但我只想检查是否支持占位符,而不是用户使用的浏览器的版本/名称。
所以在理想情况下,我想做一些类似的事情
<body>
<script>
if (placeholderIsNotSupported) {
<b>Username</b>;
}
</script>
<input type = "text" placeholder ="Username">
</body>
除了我不确定javascript位。感谢您的帮助!
发布于 2011-11-25 09:00:57
function placeholderIsSupported() {
var test = document.createElement('input');
return ('placeholder' in test);
}
我使用jQuery-ized version作为起点。(只是在该做的事情上给予表扬。)
发布于 2012-11-19 16:10:00
或者只是:
if (document.createElement("input").placeholder == undefined) {
// Placeholder is not supported
}
发布于 2016-02-26 02:42:15
另一种不需要在内存中创建必须进行GC的输入元素的方法:
if ('placeholder' in HTMLInputElement.prototype) {
...
}
https://stackoverflow.com/questions/8263891
复制相似问题