怎样动态在SVG的Javascript中动态创建文本元素(
1<text> </text>
)
---------------------------------------------------------------
这里是英文测试,中文测试要注意编码:
1<svg height="500" width="600">
2<script>
3<![CDATA[
4var step = 100;
5function cree_text(evt)
6{
7svgdoc=evt.getTarget().getOwnerDocument();
8node=svgdoc.createElement("text");
9node.setAttribute("x","50");
10node.setAttribute("y",step);
11node.setAttribute("style","text-anchor:start;font-size:24;font-family:Arial;fill:red");
12texte=svgdoc.createTextNode("This Is Added By appendChild.");
13node.appendChild(texte);
14ou=svgdoc.getElementById("net_lover");
15ou.appendChild(node);
16step=step+30
17}
18]]>
19</script>
20<g id="net_lover"></g>
21<text fill="#0099FF" id="mxh" onclick="cree_text(evt);" style="font-size:16pt;font-weight:bold" x="10" y="40">http://colorweb.go.163.com[Click Here Add New Text]</text>
22</svg>