碎碎念:一个小例子来记忆下XML DOM的appendChild和removeChild的使用
2010-10-20 14:46
459 查看
最近使用notepad写HTML,结果document拼错了,导致一开始写对的东西擦掉重写,差点误解了removeChild的作用,这个也搞定了jQuery里文档操作的几个方法warp时的技巧问题了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <title>文档</title> </head> <mce:style type="text/css"><!-- #panel1,#panel2 { width:500px; height:500px; float:left; border:1px solid #000; } .t { height:30px; width:30px; margin:2px; float:left; } #div1 { background-color:red; } #div2 { background-color:orange; } #div3 { background-color:yellow; } #div4 { background-color:blue; } #div5 { background-color:green; } #div6 { background-color:gary; } #div7 { background-color:black; } #div8 { background-color:#eee; } #div9 { background-color:#ccc; } #div10 { background-color:#ddd; } --></mce:style><style type="text/css" mce_bogus="1">#panel1,#panel2 { width:500px; height:500px; float:left; border:1px solid #000; } .t { height:30px; width:30px; margin:2px; float:left; } #div1 { background-color:red; } #div2 { background-color:orange; } #div3 { background-color:yellow; } #div4 { background-color:blue; } #div5 { background-color:green; } #div6 { background-color:gary; } #div7 { background-color:black; } #div8 { background-color:#eee; } #div9 { background-color:#ccc; } #div10 { background-color:#ddd; }</style> <mce:script type="text/javascript"><!-- window.onload = function() { document.getElementById("pop").onclick = function() { var cols = document.getElementById("panel1").getElementsByTagName("div"); if(!!cols.length) { var tmp = cols[0]; tmp = document.getElementById("panel1").removeChild(tmp); document.getElementById("panel2").appendChild(tmp); } }; document.getElementById("push").onclick = function() { var cols = document.getElementById("panel2").getElementsByTagName("div"); if(!!cols.length) { var tmp = cols[0]; tmp = document.getElementById("panel2").removeChild(tmp); document.getElementById("panel1").appendChild(tmp); } }; }; // --></mce:script> <body> <input type="button" id="pop" value="pop" /> <input type="button" id="push" value="push" /> <div id="panel1"> <div class="t" id="div1"></div> <div class="t" id="div2"></div> <div class="t" id="div3"></div> <div class="t" id="div4"></div> <div class="t" id="div5"></div> <div class="t" id="div6"></div> <div class="t" id="div7"></div> <div class="t" id="div8"></div> <div class="t" id="div9"></div> <div class="t" id="div10"></div> </div> <div id="panel2"> </div> </body> </html>
相关文章推荐
- php pthreads 多线程扩展的使用:一个较为稳定例子。
- Flex4中 一个使用Module的例子
- C#使用lock产生死锁的一个例子
- 一个使用sql实现分页的例子
- 一个简单的epoll使用例子
- 一个使用DownloadManager下载文件的小例子
- 网上找的一个表单验证类及使用例子(稍微修改了下)
- [Android]一个简单使用Handler做Timer的例子
- Java序列输入流的一个使用例子
- 使用JNDI的一个简单iBatis的例子
- 使用Junit测试一个 spring静态工厂实例化bean 的例子,所有代码都没有问题,但是出现java.lang.IllegalArgumentException异常
- 使用JSP + JAVABEAN + XML 开发的一个例子
- 一个最简单的使用Entity Framework 查询SQL 数据库的例子
- android使用Broadcast的一个例子
- 一个Excel导入SQL server的例子(分别使用游标、CTE、master..spt_values实现)
- 在看官方的例子时候由一个grid实例,在每一行之前有个加号,展开可以显示内容,在实际应用中还是非常有用的,照搬例子的代码,发现老是提示对象不存在,查阅资料后发现是没有加载插件,这里和大家分享下Ext.grid.RowExpander插件的使用,
- 使用 acl_cpp 库中的 http_request 类实现一个 HTTP 客户端请求的例子
- 使用js中常用的鼠标事件实现一个拖拽的例子
- 使用ntdsutil工具删除已不存的的DS对象的一个例子
- 用于提供一个校验和计算的例子,如何使用该文件的CRC - 32校验引擎。