6

例子:

<div> Hello World </div>

<svg>
<div> From SVG Land</div>
</svg>

问题:

尽管有标签,SVG 对象是单独解析的,而不是 dom 树的某个适当部分吗?如何在 SVG 元素中获取 DIV?

4

1 回答 1

8

正如@Stasik 所提到的,可以使用foreignObject。

例子:

<svg>
    <foreignObject width="100" height="50"
               requiredExtensions="http://www.w3.org/1999/xhtml">
      <!-- XHTML content goes here -->
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>Here is a paragraph that requires word wrap</p>
      </body>
    </foreignObject>
<svg>

摘自: https ://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject

于 2017-11-15T05:41:30.297 回答