javascript - How to get all attribute names of an img tag node using js?
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:31:49
0
4
1464
<img src="" alt="1223" src="hha"/>
<img src=".."/>

Assume that there are many img tags with a structure similar to the above, but the number of attributes of each img tag is unknown (that is, some may only have one src attribute). How to obtain all attribute names of each img tag? (not an attribute value)?

过去多啦不再A梦
过去多啦不再A梦

reply all(4)
阿神

https://developer.mozilla.org...

仅有的幸福
[].map.call(document.querySelector(Selector).attributes, (item) => {return item.name})
为情所困
// html为 <p class="ha" id="pEle"></p>
var pEle = document.querySelector('#pEle');  //得到数组
var attrs = pEle.attributes;  //得到所有属性
var attrsArray = Array.prototype.slice.call(attrs);      //转换为数组形式
console.log(attrsArray);    // [class,id]
某草草

Use ES6 object unwinding:

[...document.querySelector('selector').attributes]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template