window.onload = function(){
var inputElement = document.getElementsByTagName('input');
console.log(inputElement);
console.log(inputElement.hasAttribute('placeholder'));
if(inputElement.hasAttribute('placeholder')){
console.log('true');
}
};
我不断收到window.onload上的TypeError。可能有人点什么错,我试图检查输入的元素有一个占位符属性访问占位符属性
仔细看:它是getElement ** s ByTagName - 复数。 – georg 2015-02-09 20:46:31
就像你有一个* array *的元素,而不是元素本身。你需要循环检查每一个。 – 2015-02-09 20:47:33
基本上[为什么getElementsByClassName不适合我的副本?它返回什么?](http://stackoverflow.com/questions/10693845/why-getelementsbyclassname-does-not-work-for-me-what-does-it-return)(但这是为'getElementsByTagName'而不是'... ClassName') – apsillers 2015-02-09 20:52:44