拖拉表格的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里使用Dom操作Xml
Jan 22 Javascript
jquery Firefox3.5中操作select的问题
Jul 10 Javascript
jQuery插件原来如此简单 jQuery插件的机制及实战
Feb 07 Javascript
jquery easyui 结合jsp简单展现table数据示例
Apr 18 Javascript
jQuery中:empty选择器用法实例
Dec 30 Javascript
JS+JSP通过img标签调用实现静态页面访问次数统计的方法
Dec 14 Javascript
jQuery+Ajax实现无刷新操作
Jan 04 Javascript
JS动态增删表格行的方法
Mar 03 Javascript
jQuery的层级查找方式分析
Jun 16 Javascript
详解JavaScript对象类型
Jun 16 Javascript
让你5分钟掌握9个JavaScript小技巧
Jun 09 Javascript
使用vue cli4.x搭建vue项目的过程详解
May 08 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
最令PHP初学者头痛的十四个问题
2006/07/12 PHP
新浪新闻小偷
2006/10/09 PHP
坏狼的PHP学习教程之第1天
2008/06/15 PHP
php动态生成JavaScript代码
2009/03/09 PHP
两个开源的Php输出Excel文件类
2010/02/08 PHP
php empty函数判断mysql表单是否为空
2010/04/12 PHP
与文件上传有关的php配置参数总结
2013/06/14 PHP
php jq jquery getJSON跨域提交数据完整版
2013/09/13 PHP
PHP自带方法验证邮箱是否存在
2016/02/01 PHP
Yii2.0 模态弹出框+ajax提交表单
2016/05/22 PHP
PHP树形结构tree类用法示例
2019/02/01 PHP
jquery如何把数组变为字符串传到服务端并处理
2014/04/30 Javascript
jquery uploadify 在FF下无效的解决办法
2014/09/26 Javascript
JavaScript实现同步于本地时间的动态时间显示方法
2015/02/02 Javascript
关于JS中prototype的理解
2015/09/07 Javascript
jquery实现的点击翻书效果代码
2015/11/04 Javascript
vue制作加载更多功能的正确打开方式
2016/10/12 Javascript
jquery实现下拉框左右选择功能
2017/02/21 Javascript
SpringMVC+bootstrap table实例详解
2017/06/02 Javascript
Vuex中mutations与actions的区别详解
2018/03/01 Javascript
JS实现左边列表移到到右边列表功能
2018/03/28 Javascript
浅析JS中回调函数及用法
2018/07/25 Javascript
python验证码图片处理(二值化)
2019/11/01 Python
Python使用pymysql模块操作mysql增删改查实例分析
2019/12/19 Python
python GUI库图形界面开发之PyQt5切换按钮控件QPushButton详细使用方法与实例
2020/02/28 Python
欧洲领先的技术商店:eibmarkt.com
2019/05/10 全球购物
TobyDeals美国:在电子产品上获得最好的优惠和折扣
2019/08/11 全球购物
商场活动策划方案
2014/01/24 职场文书
幼儿园庆六一活动方案
2014/03/06 职场文书
竞争上岗演讲稿范文
2014/05/12 职场文书
2014第二批党员干部对照“四风”找差距检查材料思想汇报
2014/09/18 职场文书
2015年个人自我剖析材料
2014/12/29 职场文书
小班教师个人总结
2015/02/05 职场文书
重阳节活动主持词
2015/07/04 职场文书
导游词之白茶谷九龙峡
2019/10/23 职场文书
Mysql数据库表中为什么有索引却没有提高查询速度
2022/02/24 MySQL