http://topic.csdn.net/t/20060106/08/4500927.html
<div id="mContainer" name="mContainer">
<div id="a0" name="nContainer">nContainer[0]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
<div id="a1" name="nContainer">nContainer[1]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
<div id="a2" name="nContainer">nContainer[2]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
<div id="a3" name="nContainer">nContainer[3]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
<div id="a4" name="nContainer">nContainer[4]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
<div id="a5" name="nContainer">nContainer[5]<input type="button" value="上" onclick="doSwapNode(0,this.parentNode);"/><input type="button" value="下" onclick="doSwapNode(1,this.parentNode);"/></div>
</div>
<SCRIPT LANGUAGE="JavaScript">
var activeNode = -1;
var allObj=new Array();
var topObj;
var objLength;
function doSwapNode(direction,obj)
{
activeNode = findNode(obj);
if(activeNode==-1)return;
mDIV = allObj[activeNode].cloneNode(true);
if(!direction)
{
if(activeNode-1<0)return;
topObj.insertBefore(mDIV,allObj[activeNode-1]);
topObj.removeChild(allObj[activeNode]);
}
else
{
if(activeNode+1==objLength)return;
if(activeNode+2==objLength)
{
if(document.all)
{
topObj.insertBefore(mDIV);
topObj.removeChild(allObj[activeNode]);
}
else
{
topObj.insertBefore(mDIV,allObj[objLength+2]);
topObj.removeChild(allObj[activeNode]);
}
}
else
{
topObj.insertBefore(mDIV,allObj[activeNode+2]);
topObj.removeChild(allObj[activeNode]);
}
}
}
function findNode(obj)
{
topObj = document.getElementById("mContainer");
var allObj1 = topObj.getElementsByTagName("DIV");
//objLength=allObj.length;
for(var i=0; i<allObj1.length; i++)
{
if(isNaN(parseInt(allObj1[i].id)))
{
allObj[i]=allObj1[i];
}
}
objLength = allObj.length;
for(var i=0;i<objLength;i++)
{
if(allObj[i] == obj)
{
return i;
break;
}
}
}
</SCRIPT>