如何循环遍历所有添加的DOM属性(不是browser ones)?
示例DOM:
var div = document.createElement('div');
div['newProp1'] = '123';
div['newProp2'] = true;
div['someOtherProp'] = false;
...
...
假设我不知道“新”属性的名称,我该如何访问它们?
答案 0 :(得分:0)
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 );