Javascript 如何访问JS for<;g>;在SVG中
对于操作,svg需要访问svg组Javascript 如何访问JS for<;g>;在SVG中,javascript,jquery,svg,Javascript,Jquery,Svg,对于操作,svg需要访问svg组 <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
id="svg_main" >
<g id="layer1" x="50" y="50" width="60">
id="path3047"
style="fill:#008000" />
</svg>
id=“path3047”
style=“fill:#008000”/>
如何到达id=“layer1”
var testMapObj=document.getElementById('my_obj').contentDocument;
console.log(testMapObj);
var levelMy=testMapObj.getElementById('level1');
//或
//$(文档).on(“DOMContentLoaded”,函数(){
//var theSvgDocument=document.getElementById(“my_obj”).getSVGDocument();
//theSvgElement=theSvgDocument.document元素;
// });
不工作。为什么?
如何修复它?(解决此问题的最佳方法是什么?这将允许您访问
中的
元素:
假设您只使用了id
一次,您可以这样做:
var g = $('#layer1');
我猜这是一个复制粘贴错误,但是你知道你有一个无效的节点,对吗
id=“path3047 style=“fill:#008000”/>
没有起始-
var g = $('svg').children('#layer1');
var g = $('#layer1');