以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  SVG 修改文字内容问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=125912)


--  作者:wptest
--  发布时间:12/3/2012 11:02:00 AM

--  SVG 修改文字内容问题

有这么一段代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en"
       xmlns="http://www.w3.org/1999/xhtml"
       xmlns:svg="http://www.w3.org/2000/svg">
<head>
   <meta http-equiv="X-UA-Compatible" content="IE=9"/>
<script type="application/javascript">
function mousePos(evt)
{
cx=evt.clientX;
cy=evt.clientY;
root=evt.target.ownerDocument;
//root.getElementById("pos1").firstChild.setData("Client: "+cx+" "+cy);
root.getElementById("pos1").firstChild.nodeValue="Client: "+cx+" "+cy;
}
</script>
</head>

<body>
<svg id="theSvgElement" xmlns="http://www.w3.org/2000/svg"  width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" onmousemove="mousePos(evt)">
<rect x="0" y="0" width="400" height="400" style="stroke-width:1; stroke:black;fill:white"/>
<text id="pos1" x="5" y="20" style="font-size:15">ccc</text>
<text id="pos2" x="5" y="40" style="font-size:15">?</text>
</svg>
</body>

</html>

上面的代码中红色部分分别使用了setData()方法和nodeValue属性重置字符串,实验的结果发现,setData()根本不起任何效果,nodeValue解决了此问题,想问问有没有知道为什么呢


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
2,015.015ms