以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  SVG中Text的值怎么动态赋?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=15071)


--  作者:moonsky731
--  发布时间:3/4/2005 11:29:00 AM

--  SVG中Text的值怎么动态赋?
function rectProd(SVGNode)
{
        //svgDoc已经得到
 var otext = svgDoc.createElement("text");
 otext.setAttribute("x",200);
 otext.setAttribute("y",200);
 otext.setAttribute("font-size",20);
 otext.text = "ddd";        ------------------>这里
 SVGNode.parentNode.appendChild(otext);        
}
动态构造一个g的text节点,节点其他属性都成功了,而且也已经append上去了,但是
<text x="200" y="60" font-size="20">ddd</text>的"ddd"没有打上去,现在print节点出来是<text x="200" y="60" font-size="20"/>,请问怎么把ddd赋上去?
--  作者:sunlice
--  发布时间:3/4/2005 2:31:00 PM

--  
var title;
title="ddd";
var text = SVGDoc.createTextNode(title);
    var tspan = SVGDoc.createElement('tspan');
    
    tspan.appendChild(text);

    var label = SVGDoc.createElement('text');
    label.setAttribute('id', id + '_label');
    label.setAttribute('x', 10);
    label.setAttribute('y', 20);   
    label.setAttribute('fill', '#000000');
    label.setAttribute('width', 200);
    label.setAttribute('text-anchor', "start");
    label.setAttribute('pointer-events', 'none');

    label.appendChild(tspan);


--  作者:moonsky731
--  发布时间:3/4/2005 2:43:00 PM

--  
不行得嘛,而且我只是问一个地方的那一句,相当于赋一个节点的值,不用这样append过来,append过去吧
--  作者:yuxi2000
--  发布时间:3/14/2005 12:53:00 PM

--  
http://yuxi2000.blogchina.com
我的博客上面有一个类似例子,看看吧
--  作者:SCYANGYU
--  发布时间:3/16/2005 12:07:00 PM

--  
学习一把!

谢谢!


--  作者:moonsky731
--  发布时间:3/16/2005 2:46:00 PM

--  
今天看到有人回复了,才想起有我发过这么一篇帖子
其实自己早就解决了,其实很简单
因为SVG的text element没有nodeValue属性,它的nodeValue属性在其下firstChild节点,所以
只需要 textElement.firstChild.nodeValue= "ddd"就可以了;

--  作者:henrybenben
--  发布时间:4/13/2005 11:06:00 PM

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