1、2中:(1)、JS对象的属性:"for (z in ??)"
(2)、DOM节点的属性:"???.attrributes;"
2、举例子:
window.onload = function(evt) { var text01 = document.getElementById("text01"); // text01.removeAttribute("letter-spacing"); // delete text01.letterSpacing; for (z in text01) console.log(z + " --> " + text01[z]); /* https://segmentfault.com/q/1010000009666240?_ea=2009998 var divEle = document.querySelector(‘#divEle‘); //得到数组 var attrs = divEle.attributes; //得到所有属性 var attrsArray = Array.prototype.slice.call(attrs); //转换为数组形式 console.log(attrsArray); // [class,id] */ var attrs = text01.attributes; console.log("attrs : " + attrs); console.log("attrs[0] : " + attrs[0]); console.log(""); for (var i=0; i<attrs.length; i++) { console.log(attrs[i].name + " : " + attrs[i].value); } };
3、
4、
5、
原文地址:https://www.cnblogs.com/h5skill/p/9537863.html
时间: 2024-11-25 23:29:31