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> AboutMove up-down example of the SELECT list option with the jquery operation