拖拉表格的JS函数


Posted in Javascript onNovember 20, 2008

JS: 

/* 
@parem object the tbody's object 
@parem object tr's object (must be null) 
@parem string the className of onmousedown 
@parem string the className of onmouseout 
*/ 
function order(tt,old,classover,classout) { 
var sf = arguments.callee; //get the function self 
var trs = tt.getElementsByTagName('tr'); 
for(var i=0;i<trs.length;i++) { 
trs[i].onmousedown = function () { 
if(this.style.cursor == 'move') { 
return false; 
} 
classout = this.className; 
this.className = classover; 
this.style.cursor = 'move'; 
old = this; 
} 
trs[i].onmouseover = function () { 
if(this.style.cursor == 'move' || !old) { 
return false; 
} 
var tmp_old = old.cloneNode(true); 
var tmp_now = this.cloneNode(true); 
var p = this.parentNode; 
p.replaceChild(tmp_now,old); 
p.replaceChild(tmp_old,this); 
sf(tt,tmp_old,classover,classout); 
} 
trs[i].onmouseout = function () { 
//this.className = classout; 
} 
trs[i].onmouseup = function () { 
this.className = classout; 
this.style.cursor = ''; 
old = null; 
} 
} 
}

示例: 
<!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=utf-8" /> 
<title>无标题文档</title> 
</head> 
<script src="js/ajax.js"></script> 
<script src="js/global.js"></script> 
<style type="text/css"> 
.table { 
background-color:red; 
} 
.table td { 
background-color:#eeeeee; 
} 
.now td{ 
background-color:red; 
} 
</style> 
<script type="text/javascript"> 
<!-- 
window.onload = function () { 
order(document.getElementById('tt'),null,"now"); 
} 
/* 
@parem object the tbody's object 
@parem object tr's object (must be null) 
@parem string the className of onmousedown 
@parem string the className of onmouseout 
*/ 
function order(tt,old,classover,classout) { 
var sf = arguments.callee; //get the function self 
var trs = tt.getElementsByTagName('tr'); 
for(var i=0;i<trs.length;i++) { 
trs[i].onmousedown = function () { 
if(this.style.cursor == 'move') { 
return false; 
} 
classout = this.className; 
this.className = classover; 
this.style.cursor = 'move'; 
old = this; 
} 
trs[i].onmouseover = function () { 
if(this.style.cursor == 'move' || !old) { 
return false; 
} 
var tmp_old = old.cloneNode(true); 
var tmp_now = this.cloneNode(true); 
var p = this.parentNode; 
p.replaceChild(tmp_now,old); 
p.replaceChild(tmp_old,this); 
sf(tt,tmp_old,classover,classout); 
} 
trs[i].onmouseout = function () { 
//this.className = classout; 
} 
trs[i].onmouseup = function () { 
this.className = classout; 
this.style.cursor = ''; 
old = null; 
} 
} 
} 
//--> 
</script> 
<body> 
<table border="0" cellpadding="0" cellspacing="1" class="table"> 
<tbody> 
<tr > 
<td>ID</td> 
<td>记录</td> 
</tr> 
</tbody> 
<tbody id="tt"> 
<tr > 
<td>1</td> 
<td>记录</td> 
</tr> 
<tr> 
<td>2</td> 
<td>记录</td> 
</tr> 
<tr> 
<td>3</td> 
<td>记录</td> 
</tr> 
<tr> 
<td>4</td> 
<td>记录</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>
Javascript 相关文章推荐
JAVASCRIPT对象及属性
Feb 13 Javascript
jQuery遍历之next()、nextAll()方法使用实例
Nov 08 Javascript
js获得当前系统日期时间的方法
May 06 Javascript
AngularJS基础 ng-value 指令简单示例
Aug 03 Javascript
jQuery使用动画队列自定义动画操作示例
Jun 16 jQuery
Vue实现美团app的影院推荐选座功能【推荐】
Aug 29 Javascript
angular的输入和输出的使用方法
Sep 22 Javascript
jQuery实现的中英文切换功能示例
Jan 11 jQuery
记录一次开发微信网页分享的步骤
May 07 Javascript
Vue 使用计时器实现跑马灯效果的实例代码
Jul 11 Javascript
vue项目使用.env文件配置全局环境变量的方法
Oct 24 Javascript
vue 中使用print.js导出pdf操作
Nov 13 Javascript
设置下载不需要倒计时cookie(倒计时代码)
Nov 19 #Javascript
JavaScript在IE中“意外地调用了方法或属性访问”
Nov 19 #Javascript
$.ajax json数据传递方法
Nov 19 #Javascript
jquery $.ajax入门应用二
Nov 19 #Javascript
jquery $.ajax入门应用一
Nov 19 #Javascript
传递参数的标准方法(jQuery.ajax)
Nov 19 #Javascript
仿迅雷焦点广告效果(JQuery版)
Nov 19 #Javascript
You might like
PHP5 操作MySQL数据库基础代码
2009/09/29 PHP
php获取通过http协议post提交过来xml数据及解析xml
2012/12/16 PHP
wamp下修改mysql访问密码的解决方法
2013/05/07 PHP
Windows7下的php环境配置教程
2015/02/28 PHP
PHP实现HTTP断点续传的方法
2015/06/17 PHP
thinkPHP数据查询常用方法总结【select,find,getField,query】
2017/03/15 PHP
老生常谈PHP 文件写入和读取(必看篇)
2017/05/22 PHP
window.onload 加载完毕的问题及解决方案(下)
2009/07/09 Javascript
javascript forEach通用循环遍历方法
2010/10/11 Javascript
JS图片浏览组件PhotoLook的公开属性方法介绍和进阶实例代码
2010/11/09 Javascript
node.js chat程序如何实现Ajax long-polling长链接刷新模式
2012/03/13 Javascript
JS动态获取当前时间,并写到特定的区域
2013/05/03 Javascript
javascript动态创建及删除元素的方法
2014/12/22 Javascript
avalonjs实现仿微博的图片拖动特效
2015/05/06 Javascript
JavaScript代码性能优化总结(推荐)
2016/05/16 Javascript
require、backbone等重构手机图片查看器
2016/11/17 Javascript
Vue自定义指令详解
2017/07/28 Javascript
JScript实现地址选择功能
2017/08/15 Javascript
vue.js前后端数据交互之提交数据操作详解
2018/04/24 Javascript
对Vue- 动态元素属性及v-bind和v-model的区别详解
2018/08/27 Javascript
详解mpvue小程序中怎么引入iconfont字体图标
2018/10/01 Javascript
利用es6 new.target来对模拟抽象类的方法
2019/05/10 Javascript
vue 导航内容设置选中状态样式的例子
2019/11/01 Javascript
Vue-drag-resize 拖拽缩放插件的使用(简单示例)
2019/12/04 Javascript
python实现的简单RPG游戏流程实例
2015/06/28 Python
numpy中的ndarray方法和属性详解
2019/05/27 Python
Python实现RabbitMQ6种消息模型的示例代码
2020/03/30 Python
Jupyter Notebook折叠输出的内容实例
2020/04/22 Python
html2canvas生成的图片偏移不完整的解决方法
2020/05/19 HTML / CSS
理肤泉英国官网:La Roche-Posay英国
2019/01/14 全球购物
大学生个人自我鉴定
2013/12/03 职场文书
后进生转化工作制度
2014/01/17 职场文书
校园活动宣传方案
2014/03/28 职场文书
出资证明书范本(标准版)
2014/09/24 职场文书
《迟到》教学反思
2016/02/24 职场文书
Python中zipfile压缩包模块的使用
2021/05/14 Python