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 = "on" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "onclick =" doswapnode (1, this. parentnode); "/> </div>
<Div id = "A1" name = "ncontainer"> ncontainer [1] <input type = "button" value = "on" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "onclick =" doswapnode (1, this. parentnode); "/> </div>
<Div id = "A2" name = "ncontainer"> ncontainer [2] <input type = "button" value = "on" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "onclick =" doswapnode (1, this. parentnode); "/> </div>
<Div id = "A3" name = "ncontainer"> ncontainer [3] <input type = "button" value = "on" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "onclick =" doswapnode (1, this. parentnode); "/> </div>
<Div id = "A4" name = "ncontainer"> ncontainer [4] <input type = "button" value = "upper" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "onclick =" doswapnode (1, this. parentnode); "/> </div>
<Div id = "A5" name = "ncontainer"> ncontainer [5] <input type = "button" value = "on" onclick = "doswapnode (0, this. parentnode); "/> <input type =" button "value =" lower "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>