如何动态替换元素中的图像?

时间:2017-01-04 10:54:03

标签: javascript jquery html5 svg

如何动态取代这张照片? (不删除html SVG元素并重新渲染)

xlink:href="http://missosology.info/forum/download/file.php?avatar=11666_1307312313.jpg"

代码: https://jsfiddle.net/bfv17f0e/

<svg class="clip-svg user-img" width="36" height="36" viewBox="0 0 560 645">
  <defs>
    <clipPath id="polygon-clip">                        
      <polygon points="270,0 0,160 0,485 270,445 560,0 0,160"></polygon>
    </clipPath>
  </defs>

  <image clip-path="url(#polygon-clip)" 
         height="100%" 
         width="100%" 
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xlink:href="http://missosology.info/forum/download/file.php?avatar=11666_1307312313.jpg"
         >   
  </image>

</svg>

修改

$('image').attr('xlink:href', 'new image'); its not working not replacing the image, how do i replace that url?

1 个答案:

答案 0 :(得分:0)

作品。

$('image').attr('xlink:href', newPath)