[英]How to add a property to an element method?
该代码看起来像document.getElementById.a = 1
。 这在IE中除外。 正如文件所说
该功能也是一个对象
可以添加属性,对吧?
尝试使用方法setAttribute
即
document.getElementById('<IDofElement>').setAttribute('a',1);
您可以在“函数”原型中添加“ a”。 然后它将对所有功能可用。
Function.prototype.a = 1;
console.log(document.getElementById.a); //logs 1
console.log(document.getElementsByClassName.a); //also logs 1
这不是最好的解决方案,但即使在IE上也应该可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.