Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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将SVG文档动态插入HTML?_Javascript_Svg - Fatal编程技术网

使用JavaScript将SVG文档动态插入HTML?

使用JavaScript将SVG文档动态插入HTML?,javascript,svg,Javascript,Svg,如何将SVG动态插入HTML 现在的问题是SVG是一个文档,我只能找到如何插入节点。我尝试了一些不同的方法将SVG转换为节点,但没有找到任何有效的方法 const svgDoc=new DOMParser().parseFromString(svgText,“text/html”); window.document.querySelector(“容器”).appendChild(svgDoc); 常量svgText=` 我的第一个可缩放矢量图形 来自SitePoint.com的实验性SVG S

如何将SVG动态插入HTML

现在的问题是SVG是一个文档,我只能找到如何插入节点。我尝试了一些不同的方法将SVG转换为节点,但没有找到任何有效的方法

const svgDoc=new DOMParser().parseFromString(svgText,“text/html”);
window.document.querySelector(“容器”).appendChild(svgDoc);
常量svgText=`
我的第一个可缩放矢量图形
来自SitePoint.com的实验性SVG
SVG
`;
用于获取文档的根元素

const svgText=`
我的第一个可缩放矢量图形
来自SitePoint.com的实验性SVG
SVG
`;
const svgDoc=new DOMParser().parseFromString(svgText,“image/svg+xml”);
window.document.querySelector(“容器”).appendChild(svgDoc.documentElement)