2012-07-10 52 views
1

我有一个普通的HTML页面,就像这个例子:编辑外部SVG图形通过JavaScript

<html> 
    <head> 
    <title>Test</title> 
    </head> 
    <body> 
    <img src='test.svg' id='myImage' /> 
    </body> 
</html> 

是它在某种程度上可以编辑包含在'img'-TAG中的SVG图像?我想添加像circle或animate之类的元素。

感谢您的帮助。

+0

可能重复http://stackoverflow.com/questions/8102528/how-do-you-access-the-contents -of-an-svg-file-in-img-element) – 2012-07-11 14:01:04

回答

1

你应该直接在html中使用svg以便能够轻松地操纵svg。如果你有一个外部文件,你可以通过ajax加载它来避免重复的代码(或者只是把它包含在服务器上)。 我的经验是,使用src属性可以更轻松地处理html中的svg。

<html> 
<body> 

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> 
    <circle cx="100" cy="50" r="40" stroke="black" 
    stroke-width="2" fill="red"/> 
</svg> 

</body> 
</html> 
的[你如何访问一个SVG文件的内容在 元素?](
+0

Hoi Adi :) dankefürd Antwort x) – 2012-07-11 21:00:56