拖拉表格的JS函数

 更新时间:2008年11月20日 23:12:06   作者:  
拉表格,一个函数调用即可
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通过元素索引号删除数组中对应元素的方法

    这篇文章主要介绍了JavaScript通过元素索引号删除数组中对应元素的方法,涉及javascript操作数组的技巧,非常具有实用价值,需要的朋友可以参考下
    2015-03-03
  • javascript实现的左右无缝滚动效果

    javascript实现的左右无缝滚动效果

    这篇文章主要介绍了javascript实现的左右无缝滚动效果,可实现左右平滑无缝滚动的效果,并且可响应鼠标滑过而停止滚动,非常简便实用,需要的朋友可以参考下
    2016-09-09
  • 配置eslint规范项目代码风格

    配置eslint规范项目代码风格

    这篇文章主要介绍了配置eslint规范项目代码风格,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-03-03
  • three.js 利用uv和ThreeBSP制作一个快递柜功能

    three.js 利用uv和ThreeBSP制作一个快递柜功能

    这篇文章主要介绍了three.js 利用uv和ThreeBSP制作一个快递柜,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-08-08
  • JavaScript Event学习第五章 高级事件注册模型

    JavaScript Event学习第五章 高级事件注册模型

    在这一章我会讲解两种高级时间注册模型:W3C和微软的。因为这两个方法都不能跨浏览器,所以在现在看来他们的使用场合并不多。
    2010-02-02
  • 如何获取元素的最终background-color

    如何获取元素的最终background-color

    本文主要介绍了如何获取元素的最终background-color的方法,具有一定的参考价值,下面跟着小编一起来看下吧
    2017-02-02
  • 基于js 本地存储(详解)

    基于js 本地存储(详解)

    下面小编就为大家带来一篇基于js 本地存储(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • JavaScript 实现下雪特效的示例代码

    JavaScript 实现下雪特效的示例代码

    这篇文章主要介绍了JavaScript 实现下雪特效的示例代码,帮助大家利用JavaScript制作特效,感兴趣的朋友可以了解下
    2020-09-09
  • ES6新特性三: Generator(生成器)函数详解

    ES6新特性三: Generator(生成器)函数详解

    这篇文章主要介绍了ES6新特性之Generator(生成器)函数,简单分析了Generator(生成器)函数的功能、定义、调用方法并结合实例形式给出了相关使用技巧,需要的朋友可以参考下
    2017-04-04
  • 详解uni-app中的样式

    详解uni-app中的样式

    这篇文章主要为大家介绍了uni-app中的样式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
    2021-11-11

最新评论