Move up-down example of the SELECT list option with the jquery operation

Source: Internet
Author: User

Introduction: This article implements a simple select list option to move up and down to help readers understand the jquery selector, some common methods of node operation

The effect of the implementation:

Share code:

1<%@ Page language="C #"autoeventwireup="true"codefile="Default.aspx.cs"inherits="Movenode_default"%>2 3<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">4 5"http://www.w3.org/1999/xhtml">6"Server">7<title> Mobile Nodes </title>8<script type="Text/javascript"Src=".. /js/jquery-1.7.2.min.js"></script>9<script type="Text/javascript"Src=".. /js/jquery-1.7.2.js"></script>Ten<script type="Text/javascript"> One  A         //implementation of the Move Down function - function Moveupordown (upordown) { -  the             //Find out how many optional nodes are in a select -             varSelecteoptionlength = $ ("#where Option"). length; -              -             //Move Node up +             if(upordown) { -                  for(vari =0; i < selecteoptionlength; i++) { +                     if($("#where Option:eq ("+ i +")"). is(": Selected")) { A  at                         if(i = =0) { -Alert"The node you selected cannot be moved at the front! "); -                              Break; -                         } -$("#where Option:eq ("+ i +")"). InsertBefore ($ ("#where Option:eq ("+ i +")"). Prev ("option")); -                     } in                 } -             } to  +             //Move node down -             Else { the                  for(vari = selecteoptionlength-1; I >=0; i--) { *                     if($("#where Option:eq ("+ i +")"). is(": Selected")) { $                         //determines whether the last node is selectedPanax Notoginseng                         if(i = = selecteoptionlength-1) { -Alert"the node you selected cannot be moved on the last side! "); the                              Break; +                         } A                         //Perform an Insert node operation the$("#where Option:eq ("+ i +")"). InsertAfter ($ ("#where Option:eq ("+ i +")"). Next ("option")); +  -                     } $                 } $             } -  -         } the</script> -Wuyi<body> the<form id="Form1"runat="Server"> -<div> Wu<Selectmultiple="multiple"Id="where"Size=" -"Name="where"> -<option value=" on">AAA</option> About<option value=" Geneva">BBB</option> $<option value="Geneva">CCC</option> -<option value="Geneva">DDD</option> -<option value=" to">EEE</option> -<option value=" .">FFF</option> A<option value=" -">GGG</option> +<option value=" ,">HHH</option> the<option value=" the">MMM</option> -<option value="Ten">NNN</option> $<option value=" One">KKK</option> the</Select> the hold down CTRL or shift to support multiple selections the<input type="Button"Value="moveUp"onclick="Moveupordown (True)"/> the<input type="Button"Value="MoveDown"onclick="Moveupordown (False)"/> -</div> in  the</form> the</body> About

Move up-down example of the SELECT list option with the jquery operation

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.