jquery implementation of the TR move up and down in the table and keep the serial number unchanged _jquery

Source: Internet
Author: User

Jquerymovetr.html

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE>jQuery-bhang< /title> <script type= "Text/javascript" src= "jquery-1.6.2.js" ></script> <script type= "text/" JavaScript "src=" Jquery-rlutil-1.6.2.js "></script> </HEAD> <BODY> <table id=" show_table_id " border= "1" > <tr> <td class= "Td_num" ><input type= "text" name= "Td_num_tn" readonly= "true" style= "border:0px; width:10px "value=" 1 "/></td> <td>aaaaaaaaaa</td> <td>@@@@@@@</td> TD align= "Center" ><input type= "button" Name= "Btn1" value= "↑ onclick=" Prevmovetrcommand (This, ' show_table_id ' , ' Td_num '); "/> <input type=" button "Name=" btn2 "value=" ↓ "onclick=" Nextmovetrcommand (This, ' show_table_id ', ' TD _num '); "/></td> <td> notes 1</td> </tr> <tr> <td class=" Td_num ">&lt ; input type= "text" Name= "TD_num_tn "readonly=" true "style=" border:0px;
      width:10px "value=" 2 "/></td> <td>bbbbbbbbbbbbb</td> <td>#########</td> &LT;TD align= "center" ><input type= "button" Name= "Btn1" value= "↑ onclick=" Prevmovetrcommand (this, ' Show_table_ Id ', ' td_num '); "/> <input type=" button "Name=" btn2 "value=" ↓ "onclick=" Nextmovetrcommand (This, ' show_table_id ', ' Td_num '); "/></td> <td> notes 2</td> </tr> <tr> <td class=" Td_num "> <input type= "text" name= "Td_num_tn" readonly= "true" style= "border:0px;
      width:10px "value=" 3 "/></td> <td>cccccccccccc</td> <td>$$$$$$$$$$$$</td> &LT;TD align= "center" ><input type= "button" Name= "Btn1" value= "↑ onclick=" Prevmovetrcommand (this, ' Show_table_ Id ', ' td_num '); "/> <input type=" button "Name=" btn2 "value=" ↓ "onclick=" Nextmovetrcommand (This, ' show_table_id ', ' Td_num '); "/></td>;td> annotation 3</td> </tr> <tr> <td class= "Td_num" ><input type= "text" Name= "Td_num_tn" Readonly= "true" style= "border:0px"; width:10px "value=" 4 "/></td> <td>ddddddddddddd</td> <td>&&&&& &&&&&&&&</td> <td align= "center" ><input type= "button" name= "BTN1" va lue= "↑" onclick= "Prevmovetrcommand (This, ' show_table_id ', ' td_num ');"/> <input type= "button" Name= "BTN2" value= "↓" onclick= "Nextmovetrcommand (This, ' show_table_id ', ' td_num ');"/></td> <td> notes 4</td> < /tr> <tr> <td class= "Td_num" ><input type= "text" name= "Td_num_tn" readonly= "true" style= "border : 0px; width:10px "value=" 5 "/></td> <td>eeeeeeeeeeeeee</td> &LT;TD&GT;***************&LT;/TD&G
      T &LT;TD align= "center" ><input type= "button" Name= "Btn1" value= "↑" onclick= "Prevmovetrcommand" (tHis, ' show_table_id ', ' td_num '); "/> <input type=" button "Name=" btn2 "value=" ↓ "onclick=" Nextmovetrcommand (This, ' show_table_id ', ' td_num '); "/></td> <td> notes 5</td> </tr> </table> &LT;/BODY&G
T </HTML>

The

jquery-rlutil-1.6.2.js code is as follows:

* Function: Causes the TR content in the table table with ordinal to move up and down and keep the serial number unchanged * * Function Usage Requirements: * 1, require to use this function must first refer to the Jquery-1.6.2.js file * 2, the move button's Name property must be BTN1, move down the button NA Me property must be BTN2 * 3, to have a id=show_table_id table element, this table element placed N TR set TD information, which has a TD text is an input box, input value is the serial number * 4, Require all text content to be serial number TD's Class attribute is Td_num * * @param: obj is a button object * @param: TABLE_SELF_ID is the ID value of the table * @param: td_self_id for content Is the input ordinal box of TD's Class attribute value//up shift instruction function Prevmovetrcommand (obj, table_self_id, td_self_id) {*//without header writing Var $jqFirs 
 TTr = JQuery ("#" +table_self_id+ "Tr:first-child"); Gets the object of the first tr var firsttrval = $jqFirstTr. Find ("."  
+td_self_id+ "Input:nth-child (1)"). Val (); Gets the value of the input in the first tr var objval = jQuery (obj). Parent (). Parent (). Find (".") 
+td_self_id+ "Input:nth-child (1)"). Val (); 
Gets the serial number of its own TR with the header of the notation var $jqFirstTr = jQuery ("#" +table_self_id+ "Tr:nth-child (2)"); /* Get the object of the second TR/var firsttrval = $jqFirstTr. Find ("." 
 +td_self_id+ "Input:nth-child (1)"). Val (); /* Gets the ordinal number of the input value in the first TR/var objval = jQuery (obj). Parent () Parent (). Find ("."
+td_self_id+ "Input:nth-child (1)"). Val ();
  /* Obtain the serial number of its own TR/if (Objval = = Firsttrval) {/* To determine whether the first line to move upward/return; 
   }else{Prevmovetropra (obj, td_self_id);    /* Call up action method */}}/* Move operation/function Prevmovetropra (obj, td_self_id) {var $jqObj = jQuery (obj). Parent (). Parent () clone ();  /* Obtain and copy the information for TR/var $jqSublObj = jQuery (obj). Parent (). Parent (). Prev (); <span style= "font-family:arial, Helvetica, Sans-serif; " >/* Get information about the last TR */</span> $jqSublObj. Find ("." +td_self_id+ "Input:nth-child (1)"). Val ($jqSublObj. Find (".") +td_self_id+ "Input:nth-child (1)"). Val () +1); <span style= "font-family:arial, Helvetica, Sans-serif;"  >/* Add the last TR serial number to 1*/</span> jQuery (obj). Parent (). Parent (). HTML (""). Append ($jqSublObj. html ()); <span style= "font-family:arial, Helvetica, Sans-serif;" > * To empty and insert the previous information */</span> $jqObj. Find ("." +td_self_id+ "Input:nth-child (1)"). Val ($jqObj. Find (".")    +td_self_id+ "Input:nth-child (1)"). Val ())-1); /* To reduce the 1*/by its own TR serial number $jQsublobj.html (""). Append ($jqObj. html ()); /* Empty the last TR and insert the temporarily saved TR information/$JQOBJ. Remove (); /* Delete Redundant JQuery objects/* * Move instruction/function Nextmovetrcommand (obj, table_self_id, td_self_id) {var $jqLastTr = jQuery ("#" +table_self_id+ "Tr:last-child"); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* gets the object of the last tr */</span> var lasttrval = $jqLastTr. Find ("."    +td_self_id+ "Input:nth-child (1)"). Val (); /* Get the serial number of the last TR/var objval = jQuery (obj). Parent () parent (). Find (".") +td_self_id+ "Input:nth-child (1)"). Val (); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* Obtain its own TR serial number */</span> if (objval = = lasttrval) {<span style= "font-family:arial, Helvetica, Sans-serif;"
  >/* judge whether want to move the last line down */</span> return;  }else{Nextmovetropra (obj, td_self_id); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* invoke the Move Down action method */</span><span style= "Font-family:arial, Helvetica, Sans-serif;" ><span style= "White-space:pre" > </span>}&LT;/SPAN&GT}/* Move Down operation/function Nextmovetropra (obj, td_self_id) {var $jqObj = jQuery (obj). Parent (). Parent () clone (); &L T;span style= "font-family:arial, Helvetica, Sans-serif;" >/* Obtain and copy the information of its own tr */</span> var $jqSiblObj = jQuery (obj). Parent (). Parent (). Next (); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* Get the next TR info/</span> $jqSiblObj. Find ("." +td_self_id+ "Input:nth-child (1)"). Val ($jqSiblObj. Find (".") +td_self_id+ "Input:nth-child (1)"). Val ())-1); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* The next TR serial number minus 1*/</span><span style= "font-family:arial, Helvetica, Sans-serif;" > </span> jQuery (obj). Parent (). HTML (""). Append ($jqSiblObj. html ()); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* its own TR empty and inserts the next TR information */</span><span style= "font-family:arial, Helvetica, Sans-serif;" > </span> $jqObj. Find ("." +td_self_id+ "Input:nth-child (1)"). Val ($jqObj. Find (".") +td_self_id+ "inPut:nth-child (1) "). Val ()) +1); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* the TR serial number plus 1*/</span><span style= "font-family:arial, Helvetica, Sans-serif;" > </span> $jqSiblObj. html (""). Append ($jqObj. html ()); <span style= "font-family:arial, Helvetica, Sans-serif;" >/* the next tr to empty and insert the temporarily saved TR information */</span><span style= "font-family:arial, Helvetica, Sans-serif;"  > </span> $jqObj. Remove ();
 /* Delete Redundant jquery objects copied * *

The

jswension.html code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <title>javascript splicing Edition ;/title> <meta http-equiv= "Content-type" content= "text/html"; CHARSET=GBK "> <script type=" text/javascript "src=" jquery-1.6.2.js "></script> <script type=" text/ JavaScript "src=" Jquery-rlutil-1.6.2.js "></script> <script type=" Text/javascript "> [color=green]/*o Nclick=prevmovetrcommand (This, ' show_table_id ', ' td_num ');
    This place must not take a space, otherwise garbled */[/color] JQuery (document). Ready (function () {var str = "";
    STR + + "<tr>"; STR + + <td class= ' td_num ' ><input type= ' text ' name= ' td_num_tn ' readonly= ' true ' style= ' border:0px;
    width:10px ' value= ' 1 '/></td> ';
    STR + + "<td>aaaaaaaaaa</td>";
    STR + + "<td>@@@@@@@</td>"; STR + + <td align= ' center ' ><input type= ' button ' name= ' btn1 ' value= ' ↑ ' Onclick=prevmovetrcommand (this, ' Show_ table_id ', ' td_num ');
    /> "; str = "<input type= ' button ' name= ' btn2 ' value= ' ↓ ' Onclick=nextmovetrcommand (this, ' show_table_id ', ' td_num ');
    /></td> ";
    STR + + "<td> annotation 1</td>";
    STR + + "</tr>";
    STR + + "<tr>"; STR + + <td class= ' td_num ' ><input type= ' text ' name= ' td_num_tn ' readonly= ' true ' style= ' border:0px;
    width:10px ' value= ' 2 '/></td> ';
    STR + + "<td>bbbbbbbbbbbbb</td>";
    STR + + "<td>#########</td>"; STR + + <td align= ' center ' ><input type= ' button ' name= ' btn1 ' value= ' ↑ ' Onclick=prevmovetrcommand (this, ' Show_ table_id ', ' td_num ');
    /> "; STR + + <input type= ' button ' name= ' btn2 ' value= ' ↓ ' Onclick=nextmovetrcommand (this, ' show_table_id ', ' td_num ');
    /></td> ";
    STR + + "<td> annotation 2</td>";
    STR + + "</tr>";
    STR + + "<tr>"; STR + + <td class= ' td_num ' ><input type= ' text ' name= ' td_num_tn ' readonly= ' true ' style= ' border:0px;
    width:10px ' value= ' 3 '/></td> '; str = "<td>cccccccccccc</td> ";
    STR + + "<td>$$$$$$$$$$$$</td>"; STR + + <td align= ' center ' ><input type= ' button ' name= ' btn1 ' value= ' ↑ ' Onclick=prevmovetrcommand (this, ' Show_ table_id ', ' td_num ');
    /> "; STR + + <input type= ' button ' name= ' btn2 ' value= ' ↓ ' Onclick=nextmovetrcommand (this, ' show_table_id ', ' td_num ');
    /></td> ";
    STR + + "<td> annotation 3</td>";
    STR + + "</tr>";
    STR + + "<tr>"; STR + + <td class= ' td_num ' ><input type= ' text ' name= ' td_num_tn ' readonly= ' true ' style= ' border:0px;
    width:10px ' value= ' 4 '/></td> ';
    STR + + "<td>ddddddddddddd</td>";
    STR + + "<td>&&&&&&&&&&&&&</td>"; STR + + <td align= ' center ' ><input type= ' button ' name= ' btn1 ' value= ' ↑ ' Onclick=prevmovetrcommand (this, ' Show_ table_id ', ' td_num ');
    /> "; str = "<input type= ' button ' name= ' btn2 ' value= ' ↓ ' Onclick=nextmovetrcommand (this, ' show_table_id ', ' td_num ');
    /></td> ";
    STR + + "<td> annotation 4</td>";
    STR + + "</tr>";
    STR + + "<tr>"; STR + + <td class= ' td_num ' ><input type= ' text ' name= ' td_num_tn ' readonly= ' true ' style= ' border:0px;
    width:10px ' value= ' 5 '/></td> ';
    STR + + "<td>eeeeeeeeeeeeee</td>";
    STR + + "<td>***************</td>"; STR + + <td align= ' center ' ><input type= ' button ' name= ' btn1 ' value= ' ↑ ' Onclick=prevmovetrcommand (this, ' Show_ table_id ', ' td_num ');
    /> "; STR + + <input type= ' button ' name= ' btn2 ' value= ' ↓ ' Onclick=nextmovetrcommand (this, ' show_table_id ', ' td_num ');
    /></td> ";
    STR + + "<td> annotation 5</td>";

    STR + + "</tr>";
  $ ("#show_table_id"). html (str);
    
 });
</script> </HEAD> <BODY> <table id= "show_table_id" border= "1" ></table> </BODY> </HTML>

Above this jquery implementation table of the TR move up and down and keep the serial number of the example code is small to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.