1

我正在尝试使用 JavaScript(Google Chrome v21.0)中的 SVG。我了解如何使用基于 XML 命名空间的函数创建元素等。但是...我注意到有一大堆对象 SVG*,例如 SVGDocument。但我找不到任何关于如何使用它们的参考。例如:

doc1 = new SVGDocument()

返回:

TypeError: Illegal constructor

而任何其他参数不足的构造函数返回:

TypeError: Not enough arguments

这里发生了什么?

4

1 回答 1

2

You would create an SVG document with document.implementation.createDocument

So for SVG it would be

var dom = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg:svg', null);

or alternatively

var dt = document.implementation.createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
var dom = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg:svg', dt);

If you wanted/needed to set the document type too.

于 2012-09-28T07:01:13.750 回答