当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 由 element.appendChild(newNode) ,谈开去

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 由 element.appendChild(newNode) ,谈开去


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 171 ::
收藏到网摘: n/a

element.appendChild(newNode) 方法中,如果 newNode本身是Dom中的一个节点. 那么appendChild方法执行的不再
是append操作了,而是一个move操作. 比如说:
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

因为btn1本身是dom 中的一个节点,所以 appendChild操作会将 btn1 移动到 btn4的后面,而不是复制.
利用这个特点,我们可以用极少量的代码实现另类的文字无缝滚动.
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

呵呵,是不是很简洁呢, 这个方法我在今年五月份的时候发到了CSDN上,当时引起了许许多多的JavaScript爱好
者的大讨论, 那帖子被CSDN首页置顶,三百人参与回复讨论.
除了这个应用, appendChild的这个特性还可以在表格排序上大展身手.
注意,下面表格排序代码只是为了说明 appendChild的用法,没有在 ff中测试.
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

怎么样,有了appendChild 的大力相助,这个排序够简单吧.
关于表格的更多操作方法,和高级的自定义表格排序,请参见我在CSDN的另一个帖子(也是用appendChild实现的排序,且兼容firefox)