[英]How to change the image url in svg using jquery?
我想在给定svg标签的情况下使用下面的jquery动态更改基于图像url的id属性。 任何人都可以帮助我。
<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">
我想动态更改打击网址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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.