svg - 如何通过单击按钮将 svg 添加到工作空间?
问题描述
也许这对你来说很简单,但对我来说不是......我想要一个简单的按钮,当按下它时会在工作空间中添加一个 svg(首选圆圈)。像这样的东西https://codepen.io/davecar21/pen/jYQLEO 但我不想要动画,只是一个简单的 svg(偏好圈)。
$('button').click(function() { $('svg animate.anim1').attr("begin", 2); $('svg animate.anim2').attr("begin", 3); })
解决方案
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>
推荐阅读
- objective-c - 类簇和泛型之间有什么关系吗?
- c# - 有人可以解释这个功能是如何工作的吗?randoms.Sort((x, y) => rnd.Next(-1, 1));
- r - 有没有办法使用 R 中的 networkDynamic 包突出显示特定节点和边缘?
- java - 如何将 Java 正则表达式匹配到结果字符串?
- security - U盘上软件的反盗版措施
- javascript - 未捕获的类型错误:window.Plivo 不是构造函数
- python - 我的 Python SQLite 代码容易发生 SQL 注入吗?
- android - 带有基线文件的 android lintoptions 不起作用
- wordpress - 更改固定链接后自定义帖子类型返回 404
- android - 不同主题的 PNG 会导致 InflateException