Javascript 在opera mini中检测到占位符属性,但未使用
我使用此代码检查占位符属性是否受支持:Javascript 在opera mini中检测到占位符属性,但未使用,javascript,html,opera,Javascript,Html,Opera,我使用此代码检查占位符属性是否受支持: function placeholderIsSupported() { var test = document.createElement('input'); return typeof test.placeholder !== 'undefined'; } 如果支持占位符属性,我将在代码中隐藏标签: //Remove labels, if the placeholder attribute is supporte
function placeholderIsSupported() {
var test = document.createElement('input');
return typeof test.placeholder !== 'undefined';
}
如果支持占位符属性,我将在代码中隐藏标签:
//Remove labels, if the placeholder attribute is supported
if (placeholderIsSupported()) {
labels = document.getElementsByTagName("label");
for (i = 0; i < labels.length; i++)
{
labels[i].style.display = "none";
}
}
//如果支持占位符属性,则删除标签
如果(占位符IsSupported()){
标签=document.getElementsByTagName(“标签”);
对于(i=0;i
但是,在Android版Opera Mini 7.5中,标签是隐藏的,即使不支持占位符。有什么办法解决这个问题吗?不确定是否有帮助,但您可以尝试以下方法:
'placeholder' in document.createElement('input') && 'placeholder' in document.createElement('textarea');
这是如何进行检查的,在大多数情况下是非常可靠的
无论如何,我认为你不应该重新发明轮子,有很多方法可以帮你完成这项工作