通过jquery更新他的路径后,SVG图像转动黑色
题
我有以下HTML代码
<div>
<a id="cover"></a>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 510 680">
<rect x="0" y="0" fill="#000007" width="510" height="680"/>
<image width="510" height="680" xlink:href="../images/MSRCover.png" transform="translate(0 0)" />
</svg>
</div>
.
我正在尝试用jquery更改图像的路径,并且图像变黑。
$ = cheerio.load(data);
$('image').each(function()
{
var $img = $(this);
$(this).attr('xlink:href','My PATH').html();
});
.
我正在使用node.js和模块Cheerio。
感谢
解决方案
jQuery .Attr方法不了解命名空间。使用普通DOM SetAttributene,例如,例如
$(this)[0].setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "My PATH");
. 不隶属于 StackOverflow