var path = document.getElementsByTagName("path");
(function fillCss(){ for(var i in path){
path[i].setAttribute("fill","none");
path[i].setAttribute("stroke","black");
path[i].setAttribute("stroke-width","0.5");
}
})();样式被执行但是报错:Uncaught TypeError: path[i].setAttribute is not a function(…)
1 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
同楼上 quiet_coder 说的
直接 for (var i = 0, l = path.length; i < l; i += 1) ... 就可以了。
for-in 罗列的是对象中PropertyIsEnumerable()的属性,所以path这个类数组中所有PropertyIsEnumerable()的属性都被罗列出了,包含 <length, item, namedItem>这些
添加回答
举报
0/150
提交
取消