【转载】动态新增svg节点
2016-11-24 15:46
573 查看
原文地址:http://blog.csdn.net/tomatomas/article/details/50442497
原文作者:番茄大圣
创建svg节点时,要使用createElementNS函数并传入节点名称的命名空间。
否则创建出来的节点默认为html dom而不是svg dom。
这样的话,将其append到svg节点下时,不会显示。
原文作者:番茄大圣
创建svg节点时,要使用createElementNS函数并传入节点名称的命名空间。
否则创建出来的节点默认为html dom而不是svg dom。
这样的话,将其append到svg节点下时,不会显示。
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <meta content="width=device-width;initial-scale=1"> <script> function onLoad(){ var mysvg = document.getElementById("svg_my"); var rectObj = document.createElementNS("http://www.w3.org/2000/svg","rect"); if(rectObj){ rectObj.setAttribute("width",100); rectObj.setAttribute("height",100); rectObj.setAttribute("style","fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"); mysvg.appendChild(rectObj); alert("hello"); } } window.onload = onLoad; </script> </head> <body> <svg id="svg_my" style="border:1px solid #000;width:200px;height:200px" version="1.1" xmlns="http://www.w3.org/2000/svg"> </svg> </body> </html>
相关文章推荐
- 解决jquery中动态新增的元素节点无法触发事件问题的两种方法
- backbone中动态新增的元素节点触发事件的问题有两种解决方法
- GridView动态新增行、删除、编辑行(转载)
- HADOOP/HBase动态新增节点
- 动态图解 红黑树-新增节点
- 解决jQuery ajax动态新增节点无法触发点击事件的问题
- 关于tidb中 pd动态新增节点
- hadoop2.7.1不重启,动态删除节点和新增节点
- hadoop2.7 动态新增节点和删除节点
- hadoop2.7.1不重启,动态删除节点和新增节点
- 解决jQuery ajax动态新增节点无法触发点击事件的问题
- 3步动态新增hadoop节点
- 解决jquery中动态新增的元素节点无法触发事件问题的两种方法
- jquery中动态新增的元素节点无法触发事件解决办法
- nginx(非openresty) 实现解析uri自动upstream并支持动态新增删除(redisCluster)节点(四种方式)
- 论C/C++函数间动态内存的传递(转载)
- (转载)GCC与Obj文件,动态链接文件和ELF文件
- Visual Basic .NET 中动态加载类【转载】
- 转载 用动态代理实现AOP
- Asp.net动态生成html页面 (转载)