Dom:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>dom option Move Operation </title>6<style>7 Select {8 width:100px;9 height:85px;Ten } One A Div { -display:inline-Block; - width:50px the } -</style> - -<body> +<select id= "Unsel" size= "5" multiple><option>argentina</option><option>brazil</option ><option>Canada</option><option>Chile</option><option>China</option> <option>Cuba</option><option>Denmark</option><option>Egypt</option>< option>france</option><option>greece</option><option>spain</option></ Select> -<div> +<button onclick= "Move (this.innerhtml)" >>></button> A<button onclick= "Move (this.innerhtml)" >></button> at<button onclick= "Move (this.innerhtml)" ><</button> -<button onclick= "Move (this.innerhtml)" ><<</button> -</div> -<select id= "sel" size= "5" multiple> -</select> -<script> in function$ (ID) { - returndocument.getElementById (ID); to } + varUnsel=NULL;//Save list of all alternative countries - varSel=[];//Save a list of selected countries theWindow.onload=function(){ *unsel=$ ("Unsel"). InnerHTML $. replace (/<\/?option>/g, "")Panax Notoginseng. Match (/\b[a-za-z]+\b/g); - } the functionMove (inner) { + Switch(inner) { A Case">>"://Move All right theSel=Sel.concat (Unsel); +Unsel.length=0; - Sel.sort (); $ Break; $ Case"<<"://Move all left -Unsel=Unsel.concat (SEL); -Sel.length=0; the Unsel.sort (); - Break;Wuyi Case">"://Select item to move right the varOpts=document.queryselectorall ("#unsel option"); - //traverse each option from the back forward Wu for(vari=opts.length-1;i>=0;i--){ - if(opts[i].selected) { About //Remove the 1 elements from the I position in Unsel and press directly into the SEL $Sel.push (Unsel.splice (i,1) [0]); - } - } - Sel.sort (); A Break; + Case"<"://selected item left shift the varOpts=document.queryselectorall ("#sel option"); - for(vari=opts.length-1;i>=0;i--){ $ if(opts[i].selected) { theUnsel.push (Sel.splice (i,1) [0]); the } the } the Unsel.sort (); - Break; in } the Show (); the } About functionShow () {//update two arrays to the SELECT element the$ ("Unsel"). Innerhtml= "<option>" the+unsel.join ("</option><option>") the+ "</option>"; +$ ("sel"). Innerhtml= "<option>" -+sel.join ("</option><option>") the+ "</option>";Bayi } the</script> the</body> -Jquery:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title> Options Move Operations </title>6<script src= "Jquery.min.js" ></script>7<style>8 Select {9 width:100px;Ten height:85px; One } A - Div { -display:inline-Block; the width:50px - } -</style> - +<body> -<select id= "First" size= "5" multiple> +<option>Argentina</option> A<option>Brazil</option> at<option>Canada</option> -<option>Chile</option> -<option>China</option> -<option>Cuba</option> -<option>Denmark</option> -<option>Egypt</option> in<option>France</option> -<option>Greece</option> to<option>Spain</option> +</select> -<div> the<button id= "Add" >></button> *<button id= "Add_all" >>></button> $<button id= "Remove" ><</button>Panax Notoginseng<button id= "Remove_all" ><<</button> -</div> the<select id= "Second" size= "5" multiple> +</select> A the<script> +$ ("#add"). Click (function(){ - //Move left-selected option to the right $$ ("#first >option:selected"). AppendTo ($ ("#second")); $ }); -$ ("#add_all"). Click (function(){ -$ ("#first >option"). AppendTo ($ ("#second")); the }); -$ ("#remove"). Click (function(){Wuyi$ ("#second >option:selected"). AppendTo ($ ("#first")); the }); -$ ("#remove_all"). Click (function(){ Wu$ ("#second >option"). AppendTo ($ ("#first")); - }); About //Double-click event $$ ("#first"). DblClick (function(){ -$ ("#first >option:selected"). AppendTo ($ ("#second")); - }); -$ ("#second"). DblClick (function(){ A$ ("#second >option:selected"). AppendTo ($ ("#first")); + }); the</script> -</body> $DOM manipulation and jquery implementation options move operations