svg文件:
若想实现动态交互,text标签必须有初值(例:Hello)
方法一:
方法二:
注:方法二来自ibm developerworks,详细请参看http://www.ibm.com/developerworks/cn/xml/x-svgint/index.html
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<text id="txt" x="65" y="70" style="font-size:12px;" fill="red">Hello</text>
</svg>
若想实现动态交互,text标签必须有初值(例:Hello)
方法一:
txt = svgDocument.getElementById("txt");
txt.firstChild.nodeValue="Hello World !";
方法二:
var txt=svgDocument.getElementById("txt");
var newText = svgDocument.createTextNode("Hello World !");
txt.replaceChild(newText,txt.firstChild);
注:方法二来自ibm developerworks,详细请参看http://www.ibm.com/developerworks/cn/xml/x-svgint/index.html