DOM manipulation and jquery implementation options move operations

Source: Internet
Author: User

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)" >&gt;&gt;</button> A<button onclick= "Move (this.innerhtml)" >&gt;</button> at<button onclick= "Move (this.innerhtml)" >&lt;</button> -<button onclick= "Move (this.innerhtml)" >&lt;&lt;</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"&gt;&gt;"://Move All right theSel=Sel.concat (Unsel); +Unsel.length=0; - Sel.sort (); $                      Break; $                  Case"&lt;&lt;"://Move all left -Unsel=Unsel.concat (SEL); -Sel.length=0; the Unsel.sort (); -                      Break;Wuyi                  Case"&gt;"://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"&lt;"://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" >&gt;</button> *<button id= "Add_all" >&gt;&gt;</button> $<button id= "Remove" >&lt;</button>Panax Notoginseng<button id= "Remove_all" >&lt;&lt;</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

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.