jquery Implementation list Move up and down function _jquery

Source: Internet
Author: User

Less nonsense, we began to enter the subject.
Today we achieve a list page move up and down function. As shown in figure:

When you check the columns in the list, click Move Up or Move down to move up or down.
The HTML code is as follows:

<div> 
  <input type= button "onclick=" Up (); "Value=" Move Up "> 
  <input type=" button "onclick=" Down (); " Value= "Move Down" > 
</div> 
 <div> 
<table width= "400px" height= "" class= "MyTable" cellpadding= "5" cellspacing= "0" > 
<tr> 
 <td> serial number </td> 
 <td> name </td> 
  <td> gender </td> 
</tr> 
 <tr> 
 <td><input type= "checkbox" id= "C1"/>1 </td> 
 <td> Small one </td> 
  <td> men </td> 
</tr> 
 <tr> <td><input type= "checkbox" id= "C2"/>2</td> 
 <td> Small II </td> 
  <td> female </ td> 
</tr> 
<tr> 
 <td><input type= "checkbox" Id= "C3"/>3</td> 
 <td> </td> 
  <td> women </td> 
</tr> 
</table> 

We define a CSS style called MyTable

. mytable td,.mytable{ 
 font-size:12px; 
 color:red; 
 border:1px solid #000; 
 Text-align:center; 
 Border-collapse:collapse; 
 

And then implement up (), the Down () method is available, the code is as follows:

$.each ($ ("Table input:checked"), function () { 
  var onthis=$ (this). Parent (). parent (); 
  var getup=onthis.prev (); 
   
  if ($ (getUp). has ("input"). Size () ==0) 
  { 
   alert ("top element cannot move up"); 
   return; 
  } 
  $ (onthis). After (getUp);} 
 ); 
 function down () { 
 $.each ($ (' Table input:checked '), function () { 
  var onthis=$ (this). Parent (). parent (); 
  var getdown=onthis.next (); 
  $ (Getdown). After (onthis);} 
 ); 
 

Using the functions provided by jquery, the implementation is very simple, of course, if you want to achieve multiple columns at the same time move down, only need to add a loop can be, the core code is the top.

The above is the entire content of this article, I hope to learn from the jquery program to help.

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.