原文链接:https://blog.csdn.net/weixin_37674736/article/details/82426941
用setAttribute来设置svg的image的路径,图片无法显示
要用 image.href.baseval 才会有效
var svgDoc = document.getElementById("sketchpad");var imgSVG = document.createElementNS("http://www.w3.org/2000/svg", 'image');imgSVG.href.baseVal = "img/water.png"; //svg设置image的url图片,要用image.href.baseValimgSVG.setAttribute('width', 70);imgSVG.setAttribute('height', 70);imgSVG.setAttribute('class', 'equ');imgSVG.setAttribute('x', "150");imgSVG.setAttribute('y', "200");svgDoc.appendChild(imgSVG);
————————————————
版权声明:本文为CSDN博主「李晓怡」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_37674736/article/details/82426941