问题描述
我试图在svg里追加一个html div,我试图创建一个图。我试图使用下面的代码来追加它,但是当我使用萤火虫检查元素时。div显示在rect元素代码内,但它不显示在图形用户界面中。这是一种方法,我正在尝试或不能坐在svg内附加一个div吗?
I am trying to append an html div inside an svg, which I am trying to create a graph. I am trying to append it using the code below, but when I inspect element using firebug.. the div is shown inside "rect" element code, but it doesnt show up in the graph UI. is it something wrng with the method that I am trying or is sit imposible to append a div inside svg?
marker.append("rect").attr("width", "50px").attr("height", "50px").append("div").attr("id", function (d) { return "canvas_" + d.key.split(" ").join("_"); }).style("width", "50px").style("height", "50px");
推荐答案
不能将HTML附加到SVG可以用 foreignObject ,但它是一个兔子洞)。此外,SVG中的可见元素不能嵌套,因此元素如 circle , rect ,路径并且不能有子元素。
You can't append HTML to SVG (technically you can with foreignObject, but it's a rabbit hole). Furthermore, visible elements in SVG can't be nested, so elements such as circle, rect, path and such can't have children elements.
这篇关于是否有可能在svg元素内附加一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!