无法通过jQuery在SVG中添加图像:<;图像/>;标签变为<;img/>;
我想通过jQuery在SVG中添加项。 我可以很好地插入标签,如无法通过jQuery在SVG中添加图像:<;图像/>;标签变为<;img/>;,jquery,svg,Jquery,Svg,我想通过jQuery在SVG中添加项。 我可以很好地插入标签,如或,但我不能插入带有标签的图像 此标记自动变为,无法在SVG中显示图像: 我怎样才能防止这种情况? 如果不可能,是否有其他方法可以使用JavaScript/jQuery在SVG中插入图像。jQuery本身无法正确处理SVG操作。您可能应该使用,或者上面链接中描述的一种黑客方法。您应该使用createElements(): 尝试使用我的jQuery hack[[1]: var img = document.createElement
或
,但我不能插入带有标签的图像
此标记自动变为
,无法在SVG中显示图像:
我怎样才能防止这种情况?
如果不可能,是否有其他方法可以使用JavaScript/jQuery在SVG中插入图像。jQuery本身无法正确处理SVG操作。您可能应该使用,或者上面链接中描述的一种黑客方法。您应该使用
createElements()
:
尝试使用我的jQuery hack[[1]:
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','10');
img.setAttributeNS(null, 'visibility', 'visible');
$('svg').append(img);