javascript: 新增文字節點問題?

huajen 2010-02-04 02:44:49
您好,
希望您能帮帮忙. 以下的程序可以在IE上正常执行来新增文字节点, 但是在Firefox或chrome却无法成功, 请问是哪出了问题? 该如何改才能跨浏览器?! 谢谢!
-------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- file:unit.svg -->
<svg id="svg00" version="1.1" xmlns="http://www.w3.org/2000/svg" >
<rect id="rect0001" x="10" y="10" width="600" height="600" fill="white" stroke="black" stroke-width="2" />
<svg id="svg01" x="10" y="10" width="600" height="600" viewBox="0 0 600 600" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg" >
<g id="g001" transform="scale(1.0)">
<g id="g002" transform="translate(0,0)" fill-opacity="0.01" >
<rect id="rect0002" x="100" y="100" width="60" height="60" fill="white" stroke="blue" stroke-width="1" onmousedown="addText()"/>
</g>
</g>
<script type="text/javascript">
<![CDATA[
function addText(){
var GroupID02=document.getElementById("g002");
var textName="text0009";
var newText=document.createElement("text");
newText.setAttribute("id",textName);
newText.setAttribute("x",400);
newText.setAttribute("y",400);
newText.setAttribute("font-size",20);
newText.setAttribute("fill","red");
newText.setAttribute("fill-opacity",1);
newText.appendChild(document.createTextNode("ABCDEFG"));
GroupID02.appendChild(newText);
}
]]>
</script>
</svg>
</svg>
...全文
52 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
divspan 2010-02-09
  • 打赏
  • 举报
回复
可以參考 http://jwatt.org/svg/authoring/#namespace-aware-methods

用createElementNS試試看, 應該適用於大部分瀏覽器.
浴火_凤凰 2010-02-04
  • 打赏
  • 举报
回复
没有写过SVG,帮顶,
草根醉秋意 2010-02-04
  • 打赏
  • 举报
回复
vml ie only
svg !ie only
dh20156 2010-02-04
  • 打赏
  • 举报
回复
IE Only吧

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧