jquery to move up or down

Source: Internet
Author: User

When I recently made the report, I exported all the fields directly, but it was not very flexible. Recall that the teacher talked about the project to do the following move up and down the function of flexible control, so try it.

JS Code

function selected (thiz) {var name = Thiz.name;if (name== "right") $ ("Select[name= ' left ')"). Val (""); else$ ("Select[name= ' Right ']. Val ("");} function Shift (thiz) {var = $ ("Select[name= ' right ']"), var = $ ("Select[name= ' left ')"), if (thiz== "left" & & Right.val ()! = "") {Lrshift (right,left);} else if (thiz== "right" && left.val ()! = "") {Lrshift (left,right);} Gets the selected value}//moved from dest to Targetfunction Lrshift (dest,target) {var childrens = Dest.children (); var args = "";//alert (Dest.val ()) var dests = Dest.val () for (var x = 0; x < dests.length) {var vatemp = dests[x];target.append ("<option value=" "+vatemp+" > "+vatemp+" </option> ");//Append Target.find (" option[value= "" +vatemp+ "']"). attr ("selected", true) ;//Append Get focus for (var y = 0; y <childrens.length;y++)//Delete selected element {if (Childrens.get (y). Value==vatemp) $ (childrens.get (y)) . remove ();}} Dest.val ("");} function Shiftvalue (address) {var = $ ("Select[name= ' right ']"), var = $ ("Select[name= ' left ')"); if (Right.val () !=null) Shift (Right,addreSS); else if (Left.val ()!=null) shift (left,address);} function Shift (obj,address) {//Gets the selected value var objdata = Obj.val (); var childrens = Obj.children (); var strs = ""; for (var x = 0; x < objdata.length; X + +) {strs+= "@" +objdata[x];} Get the Location object to add var temp = null;if (address== "top") {var number = Findselect (childrens,objdata[0]); if ((--number) < 0) Return;temp = childrens.get (number);} Else{var number = Findselect (childrens,objdata[objdata.length-1]); if (++number) > Childrens.length-1) return;temp = Childrens.get (number);} Delete the selected value var n = 0;var buffer = new Array (childrens.length-objdata.length); for (var x = 0; x < childrens.length;x++) {var Value = Childrens.get (x). Value;if (Strs.indexof (value) ==-1) buffer[n++] = value;} Add a new sorted value obj.empty (), if (address== "top") {for (var y = 0, y < buffer.length;y++) {if (Buffer[y]==temp.value) {for (var x = 0; x < objdata.length; X + +) {obj.append ("<option>" +objdata[x]+ "</option>");}} Obj.append ("<option>" +buffer[y]+ "</option>");}} Else{for (var y = 0; Y < buffer.length;y++) {obj.append ("<option>" +buffer[y]+ "</option>"); if (Buffer[y]==temp.value) {for (var x = 0; x < objdata.length; {obj.append ("<option>" +objdata[x]+ "</option>");}}} Check value obj.val (objdata);} function Findselect (selects,objvalue) {var number = -1;for (var x = 0; x < selects.length; + +) {if (objvalue==selects.get (x). Value) number = x;} return number;}

Page Call

<div><div><b> not exported field </b></div><div style= "Float:left;" ><select name= "left" multiple= "multiple" onchange= "selected (This)" style= "height:350px;width:200px;" ><option value= "name" > Name </option><option value= "Express" > Courier No. </option><option value= "courier Company" > Express Company </option><option value= "First weight" > First weight </option><option value= "continued weight" > continued weight </option></ Select></div></div><div style= "Float:left;" ><div style= "margin:30px;margin-top:110px;" ><input type= "button" value= "<<" onclick= "Shift (' left ')"/></div><div style= "margin:30px; margin-top:30px; " ><input type= "button" value= ">>" onclick= "Shift (' right ')"/></div></div><div style= " margin-top:-20px; " ><div style= "margin-left:22%;" ><b> need to export field </b></div><div style= "Float:left;" ><select name= "Right" multiple= "multiple" onchange= "selected (This)" style= "height:350px;width:200px;" ><option value= "First price" > First price </option><option value= "Renew" > Renew </option><option value= "big" > Big </option><option value= "Small" > Small </option></select></div></div><div style= " Float:left; " ><div style= "margin:30px;margin-top:110px;" ><input type= "button" value= "Up" onclick= "Shiftvalue (' top ')"/></div><div style= "margin:30px; margin-top:30px; " ><input type= "button" value= "Down" onclick= "shiftvalue (' Bottom ')"/></div></div>

Related Article

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.