【问题标题】:Add svg to an html table (instead of html body)将 svg 添加到 html 表(而不是 html 正文)
【发布时间】:2016-07-13 01:26:16
【问题描述】:

我在 html 正文中有一个动画 svg,但我想把它放在一个表格单元格(4x4 表格)中。

据我了解,这是将我的 svg 链接到 html 正文的原因:

d3.xml("field.svg", function(xml) {    
svgdom = document.body.appendChild(xml.documentElement);

如何将我的 svg 链接到表格单元格 (id='c1') 而不是 html 正文?

<table id='tbl'>
    <tr>
        <td id='c1'></td>
        <td id='c2'></td>
    </tr>
    <tr>
        <td id='c3'></td>
        <td id='c4'></td>
    </tr>
</table>

【问题讨论】:

    标签: javascript html d3.js svg


    【解决方案1】:

    试试svgdom = document.getElementById('c1').appendChild(xml.documentElement)

    这行代码不是document.body,而是专门在文档中查询您想要将子元素附加到的元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      相关资源
      最近更新 更多