[英]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.