2011-03-15 84 views
16

我想第一次学习SVG,但代码似乎对块注释有问题。我使用的是:如何在SVG中创建块注释

/* This is my 
* block comment 
*/ 

当我跑我的代码,我得到以下错误:

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

这恰巧我的注释块后立即。

+0

我刚拿出所有的块注释,但它仍然有一个问题与另一行。你可以从这里的例子中找到所有的代码: http://pastie.org/private/hdaccssdbcxal8s0o81ciq 它抱怨第47列第8列,它不存在... – ardavis 2011-03-15 04:45:20

回答

33

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