44

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

/* This is my
 * block comment
 */

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

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

这恰好是在我的块评论之前。

4

2 回答 2

77

由于 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>
-->
于 2011-03-15T07:00:03.930 回答
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

于 2011-03-15T19:43:47.483 回答