使用JavaScript创建SVG标签

如何使用JavaScript创建SVG元素?我尝试了这个:


var svg = document.createElement('SVG');

    svg.setAttribute('style', 'border: 1px solid black');

    svg.setAttribute('width', '600');

    svg.setAttribute('height', '250');

    svg.setAttribute('version', '1.1');

    svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');

document.body.appendChild(svg);

但是,它将创建宽度为零,高度为零的SVG元素。


慕村9548890
浏览 1185回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript