无法通过jQuery添加SVG内的图像:tag变为

我想通过jQuery在SVG中添加项目.
我可以很好地插入标签,例如< rect />或< text />但是我无法使用标签< image /&gt ;.插入图像. 此标签变为< img />自动,无法在SVG中显示图像:
http://jsfiddle.net/G4mJf/

我该如何防止这种情况?
如果不可能,还有另一种方法可以使用JavaScript / jQuery在SVG中插入图像.

解决方法

你应该使用createElementNS():
var img = document.createElementNS('http://www.w3.org/2000/svg','image');
img.setAttributeNS(null,'height','536');
img.setAttributeNS(null,'width','536');
img.setAttributeNS('http://www.w3.org/1999/xlink','href','https://upload.wikimedia.org/wikipedia/commons/2/22/SVG_Simple_logo.svg');
img.setAttributeNS(null,'x','10');
img.setAttributeNS(null,'y','visibility','visible');
$('svg').append(img);

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...