通过javascript进行渲染

通过javascript进行渲染,javascript,image,web,svg,render,Javascript,Image,Web,Svg,Render,我一直在尝试通过javascript呈现svg图像。尝试了各种选择,但最终不得不解决这个问题 我在html中声明了一个对象id,如下所示 <object id="gauge1" type="image/svg+xml" data="gauge.svg" width="127" height="122"/> this.m_svg = document.createElement('embed'); A然后尝试使用setAttribute访问图像,但未成功。有什么建议吗 还将svg代

我一直在尝试通过javascript呈现svg图像。尝试了各种选择,但最终不得不解决这个问题

我在html中声明了一个对象id,如下所示

<object id="gauge1" type="image/svg+xml" data="gauge.svg" width="127" height="122"/>
this.m_svg = document.createElement('embed');
A然后尝试使用
setAttribute
访问图像,但未成功。有什么建议吗

还将svg代码与图像一起粘贴到此处

图片: svg代码:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g name="gauge" width="122px" height="127px">
        <image xlink:href="gauging.png" width="122" height="127"/>
    <circle id="led" cx="39" cy="76" r="5" style="fill: #999; stroke: none">
        <animateColor id="ledAnimation" attributeName="fill" attributeType="css" begin="0s" dur="1s"
        values="none;#f88;#f00;#f88;none;" repeatCount="0"/>
    </circle>
        <g id="needle" transform="rotate(0,62,62)">
            <circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/>
            <rect transform="rotate(-130,62,62)" name="arrow"  x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/>
            <polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/>
        </g>
        <text id="value" x="51" y="98" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text>
    </g>
</svg>


PS:已经尝试过这个.m_svg.innerHTML=svg代码(在safari上不起作用)

请确保您的标题设置正确,我知道webkit的svg实现会有一点选择性,除非标题设置为:

<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />

欲了解更多信息,请点击此处:

演示如何访问
标记内容中的元素

啊,好的。我对SVG总是有问题,现在通常只是使用Raphael使它更容易复制另一个可能的复制品:它不是这个问题的复制品。在这个问题中,图像被加载,如何访问图像的内容是一个问题。第一个链接再次提到第二个链接。因此,这也不是重复。不确定您接下来要做什么,其他问题的答案确实涵盖了从脚本和脚本中访问svg内容。