JS:
CopyCode The Code is as follows :/*
@ 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;
}
}
}
Example: Copy code The Code is as follows: <! 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> untitled document </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> record </TD>
</Tr>
</Tbody>
<Tbody id = "TT">
<Tr>
<TD> 1 </TD>
<TD> record </TD>
</Tr>
<Tr>
<TD> 2 </TD>
<TD> record </TD>
</Tr>
<Tr>
<TD> 3 </TD>
<TD> record </TD>
</Tr>
<Tr>
<TD> 4 </TD>
<TD> record </TD>
</Tr>
</Tbody>
</Table>
</Body>
</Html>