.removableobj
{
height:25;position:relative;
}
var beginmoving=false;
var sourceobj=null;
var objectobj=null;
function mousedowntomove(obj){
obj.style.zindex=1;
obj.mousedowny=event.clienty;
obj.mousedownx=event.clientx;
beginmoving=true;
obj.setcapture();
sourceobj=obj;
objectobj=null;
}
function mousemovetomove(obj){
if(!beginmoving) return false;
obj.style.top = (event.clienty-obj.mousedowny);
obj.style.left = (event.clientx-obj.mousedownx);
}
function mouseuptomove(obj){
if(!beginmoving) return false;
obj.releasecapture();
obj.style.top=0;
obj.style.left=0;
obj.style.zindex=0;
beginmoving=false;
window.settimeout("swapfun()",10);
}
function mouseoverfun(obj)
{
objectobj=obj;
}
function swapfun()
{
if(sourceobj!=null && objectobj!=null )
sourceobj.swapnode(objectobj);
sourceobj=null;
objectobj=null;
}
用鼠标移动td(本代码也适合用鼠标进行其它对象的对换(如table,div等))
a1 | a2 |
b1 | b2 |
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]