拖拉表格的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 相关文章推荐
js 跨域和ajax 跨域问题小结
Jul 01 Javascript
js 创建书签小工具之理论
Feb 25 Javascript
jquery 操作DOM的基本用法分享
Apr 05 Javascript
XMLHttpRequest处理xml格式的返回数据(示例代码)
Nov 21 Javascript
我的Node.js学习之路(二)NPM模块管理
Jul 06 Javascript
Javascript中的关键字和保留字整理
Oct 16 Javascript
js实现具有高亮显示效果的多级菜单代码
Sep 01 Javascript
jquery获取css的color值返回RGB的方法
Dec 18 Javascript
jQuery Ajax实现Select多级关联动态绑定数据的实例代码
Oct 26 jQuery
VUE+elementui面包屑实现动态路由详解
Nov 04 Javascript
JS数组转字符串实现方法解析
Sep 04 Javascript
jquery实现点击左右按钮切换图片
Jan 27 jQuery
设置下载不需要倒计时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排序算法(冒泡排序,快速排序)
2012/10/09 PHP
smarty实现多级分类的方法
2014/12/05 PHP
php上传功能集后缀名判断和随机命名(强力推荐)
2015/09/10 PHP
smarty高级特性之过滤器的使用方法
2015/12/25 PHP
iOS10推送通知开发教程
2016/09/19 PHP
PHP面向对象程序设计之命名空间与自动加载类详解
2016/12/02 PHP
thinkphp 手机号和用户名同时登录
2017/01/20 PHP
php实现的pdo公共类定义与用法示例
2017/07/19 PHP
几行代码轻松搞定jquery实现flash8类似的连接效果
2007/05/03 Javascript
jquery单行文字向上滚动效果的实现代码
2014/09/05 Javascript
JS实现弹性漂浮效果的广告代码
2015/09/02 Javascript
JavaScript中各数制转换全面总结
2017/08/21 Javascript
vue2.0移除或更改的一些东西(移除index key)
2017/08/28 Javascript
Node.js 使用jade模板引擎的示例
2018/05/11 Javascript
javascript实现的时间格式加8小时功能示例
2019/06/13 Javascript
微信小程序 网络通信实现详解
2019/07/23 Javascript
关于vue里页面的缓存详解
2019/11/04 Javascript
Python实现的一个找零钱的小程序代码分享
2014/08/25 Python
在Python中操作日期和时间之gmtime()方法的使用
2015/05/22 Python
python docx 中文字体设置的操作方法
2018/05/08 Python
tensorflow 输出权重到csv或txt的实例
2018/06/14 Python
Python实现的简单读写csv文件操作示例
2018/07/12 Python
Python中list的交、并、差集获取方法示例
2019/08/01 Python
Python Django中的STATIC_URL 设置和使用方式
2020/03/27 Python
Python实现CAN报文转换工具教程
2020/05/05 Python
css3实现背景颜色渐变让图片不再是唯一的实现方式
2012/12/18 HTML / CSS
几个CSS3的flex弹性盒模型布局的简单例子演示
2016/05/12 HTML / CSS
香港永安旅游网:Wing On Travel
2017/04/10 全球购物
英国最大的经认证的有机超市:Planet Organic
2018/02/02 全球购物
英国知名化妆品网站:Revolution Beauty(原TAM Beauty)
2018/02/28 全球购物
小学红领巾中秋节广播稿
2014/01/13 职场文书
公务员更新知识培训实施方案
2014/03/31 职场文书
企业开业庆典答谢词
2015/01/20 职场文书
学校会议通知范文
2015/04/15 职场文书
Python绘画好看的星空图
2022/03/17 Python
小程序自定义轮播图圆点组件
2022/06/25 Javascript