[英]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.