如何从 SVG 地图路径获取属性值。我用了javascript <object data="https://svgur.com/i/QXQ.svg" type="image/svg+xml" id="map"></object> <script> var a = document.getElementById("map"); a.addEventListener("load",function(){ var svgDoc = a.contentDocument; var delta = svgDoc.getElementById("provinceMap"); delta.addEventListener("mousedown",function(e){ console.log(e["path"]); }, false); }, false); </script>
1 回答
跃然一笑
TA贡献1826条经验 获得超6个赞
这样你就可以
console.log(e['path'][0].getAttribute("province"));
console.log(e['path'][0].getAttribute("district"));
console.log(e['path'][0].getAttribute("title"));
添加回答
举报
0/150
提交
取消