svg.js如何将SVG添加到HTML页面

发布于 2025-01-25 00:04:49 字数 438 浏览 0 评论 0原文

我有一个页面,该页面将显示几个将从JSON数据生成的SVG图像。我创建了一个将生成SVG的JavaScript类,但我不知道如何将其添加到DOM中。

作为一个简单的例子:

<html>
    <body>
        <div class="myrow">
            *i want to add the image here*
        </div>
    </body>
</html

我尝试了类似的事情:

let x = new mysvgobject(json);
x.img.addTo('.myrow');

但是它不起作用。我认为我需要将X.img转换为HTML会理解的东西,但不知道那是什么。任何帮助将不胜感激。

I have a page that will show several svg images that will be generated from json data. I created a javascript class that will generate the svg but I don't know how to add it to the dom.

As a simple example:

<html>
    <body>
        <div class="myrow">
            *i want to add the image here*
        </div>
    </body>
</html

I tried something like:

let x = new mysvgobject(json);
x.img.addTo('.myrow');

but it doesn't work. I think I need to convert that x.img to something the HTML will understand but don't know what that might be. Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2025-02-01 00:04:49

找到答案。只需要进一步钻入班级生产的SVG,

x.img.node.outerHTML

然后将其放在页面上。

Found the answer. Just had to drill down further into the svg produced by the class with:

x.img.node.outerHTML

and drop it on the page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文