svg路径不可见

Att*_* Ch 2 javascript svg path

为什么这条路不可见?我使用javascript动态创建路径,但路径在屏幕上不可见,但它存在于DOM中.

var svg = document.getElementById('svg');
var path = document.createElementNS('http://www.w3.org/svg', 'path');
path.setAttribute('d', 'M100,100 L100,100');
path.setAttribute('style', 'stroke:black;fill:none;');
path.setAttribute('matrix', '1,0,0,1,100,100');
svg.appendChild(path);
Run Code Online (Sandbox Code Playgroud)

或者作为一个JsFiddle

Rob*_*son 6

你有两个不同的问题

  1. SVG名称空间实际上是http://www.w3.org/2000/svg

  2. 你没有画出任何地方的线,它从100,100开始并在同一个地方结束.