<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)?
仅有的幸福2017-06-12 09:33:49
[].map.call(document.querySelector(Selector).attributes, (item) => {return item.name})
为情所困2017-06-12 09:33:49
// 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]
某草草2017-06-12 09:33:49
Use ES6 object unwinding:
[...document.querySelector('selector').attributes]