Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何遍历所有添加的 DOM 属性(不是浏览器属性)?
示例 DOM:
var div = document.createElement('div'); div['newProp1'] = '123'; div['newProp2'] = true; div['someOtherProp'] = false; ... ...
假设我不知道“新”属性的名称,我该如何访问它们?
var div = document.createElement('div'); div['newProp1'] = '123'; div.newProp2 = true; div['someOtherProp'] = false; for( let prop in div ) if( div.hasOwnProperty(prop) ) console.log( prop );