如何在SVG中创建块注释
问题描述:
我想第一次学习SVG,但代码似乎对块注释有问题。我使用的是:如何在SVG中创建块注释
/* This is my
* block comment
*/
当我跑我的代码,我得到以下错误:
'return' statement outside of function
line: 116, column: 4
这恰巧我的注释块后立即。
答
由于SVG是XML,您可以使用XML风格的注释:
<!--
comment
-->
例如:
<g onclick = "setScale(1)">
<rect id = "scale1" x = "120" y = "10" width = "30" height = "30"
fill = "#ffc" stroke = "black"/>
<!--
this text describes middle rectangle
-->
<text x = "135" y = "30" text-anchor = "middle">M</text>
</g>
或者你可以排除一些代码部分:
<!--
this group is disabled for testing
<g onclick = "setScale(1)">
<rect id = "scale1" x = "120" y = "10" width = "30" height = "30"
fill = "#ffc" stroke = "black"/>
<text x = "135" y = "30" text-anchor = "middle">M</text>
</g>
-->
答
的就DOM而言,svg文档与html文档非常相似。
这条线将在所有浏览器突破:
svgDocument = evt.getTarget().getOwnerDocument();
而且可以简单地替换为:
svgDocument = document;
其实没有真正的需要创建自document
变量svgDocument
总是被定义并参照到当前文件(svg)。
请阅读https://jwatt.org/svg/authoring/,特别是https://jwatt.org/svg/authoring/#asv-getters-and-setters。
我刚拿出所有的块注释,但它仍然有一个问题与另一行。你可以从这里的例子中找到所有的代码: http://pastie.org/private/hdaccssdbcxal8s0o81ciq 它抱怨第47列第8列,它不存在... – ardavis 2011-03-15 04:45:20