Use jquery to move up and down option

Source: Internet
Author: User
Tags prev

Basic idea: Move Up: (1) Gets the index value of the currently selected element (2) determines whether the current element is the first element (3) If it is, then the move is not performed, if not, then the call to the InsertBefore method is inserted into his prev (adjacent to the One) element before
1 varup =function () {2          varSelectedIndex = $ ("#SelectedAddressIds option:selected"). index ();//gets the index of the currently selected element3          if(SelectedIndex >= 1){4                   //Insert Previous5$ ("#SelectedAddressIds option:selected"). InsertBefore ($ ("#SelectedAddressIds option:selected"). Prev (' option '));6          }7}
Move Down: (1) Gets the index value of all option elements (2) Gets the index value of the currently selected element (3) determines whether the currently selected element is the last element, if it is, does not perform a move down, and if not, calls the InsertAfter method to insert into his Next (next to) element behind.
1 varDown =function () {2             //gets the index value of the last option3             varOptionnum = $ ("#SelectedAddressIds option"). Size ()-1;4             //gets the index value of the currently selected element5             varSelectedIndex = $ ("#SelectedAddressIds option:selected"). index ();6 7             if(SelectedIndex < 6){8                 //Insert Next9$ ("#SelectedAddressIds option:selected"). InsertAfter ($ ("#SelectedAddressIds option:selected"). Next (' option '));Ten             } One}

Use jquery to move up and down option

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.