你如何在SVG中做出一个块评论

时间:2011-03-15 04:27:50

标签: svg comments block-comments

我正在尝试第一次学习SVG,但代码似乎与我的块注释有问题。我正在使用:

/* This is my
 * block comment
 */

当我运行我的代码时,我收到以下错误:

'return' statement outside of function
line: 116, column: 4

这恰好发生在我的阻止评论之前。

2 个答案:

答案 0 :(得分:47)

由于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>
-->

答案 1 :(得分:1)

就DOM而言,svg文档与html文档非常相似。

此行将在所有浏览器中中断:

svgDocument = evt.getTarget().getOwnerDocument();

可以简单地替换为:

svgDocument = document;

实际上并不需要创建变量svgDocument,因为始终定义document并引用当前文档(svg)。

请阅读https://jwatt.org/svg/authoring/,特别是https://jwatt.org/svg/authoring/#asv-getters-and-setters