Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何访问JS for<;g>;在SVG中_Javascript_Jquery_Svg - Fatal编程技术网

Javascript 如何访问JS for<;g>;在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需要访问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"
   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');