如何使用 jquery 更改 svg 中的图像 url?

How to change the image url in svg using jquery?

我想使用下面的 jquery 动态更改图像 url id 属性,我给出了 svg 标签。谁帮帮我。

<image id="background_image" width="804" height="943" preserveAspectRatio="xMinYMin" style=" pointer-events:none;background-repeat:repeat-y;" xlink:href="http://www.example.com/img/imag.png">

我想动态改变打击url http://www.example.com/img/imag.png

带有 attr 的简单选择器(如下所示)应该适合您。

$('#background_image').attr('xlink:href','newurl.com/image.png');        

使用 jQuery .attr() 更新 href

$(function() {
  $('#background_image').attr('xlink:href', 'http://placehold.it/350x150');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<image id="background_image" width="804" height="943" preserveAspectRatio="xMinYMin" style=" pointer-events:none;background-repeat:repeat-y;" xlink:href="http://www.example.com/img/imag.png">