首页 > 解决方案 > 如何通过单击按钮将 svg 添加到工作空间?

问题描述

也许这对你来说很简单,但对我来说不是......我想要一个简单的按钮,当按下它时会在工作空间中添加一个 svg(首选圆圈)。像这样的东西https://codepen.io/davecar21/pen/jYQLEO 但我不想要动画,只是一个简单的 svg(偏好圈)。

$('button').click(function() { $('svg animate.anim1').attr("begin", 2); $('svg animate.anim2').attr("begin", 3); })

标签: svg

解决方案


document.getElementById('draw').addEventListener('click', function(){

document.getElementById('here').innerHTML = 
'<svg height="100" width="100">' + 
  '<circle cx="50" cy="50" r="40" stroke="black" stroke-width="1" fill="rgba(130,130,130,0.6)">' + 
'</svg>';

});
<button id="draw">Draw Circle</button>
<div id="here"></div>


推荐阅读