is to achieve this effect, select Add to the right, all add to the right, select Delete to the left, all delete to the left.
HTML section:
Copy Code code as follows:
<body>
<div class= "Centent" >
<select multiple= "multiple" id= "Select1" style= "width:100px;height:160px"; >
<option value= "1" > Option 1</option>
<option value= "2" > Option 2</option>
<option value= "3" > Option 3</option>
<option value= "4" > Option 4</option>
<option value= "5" > Option 5</option>
<option value= "6" > Option 6</option>
<option value= "7" > Option 7</option>
</select>
<div>
<span id= "Add" > select Add to Right >></span>
<span id= "Add_all" > All add to Right >></span>
</div>
</div>
<div class= "Centent" >
<select multiple= "multiple" id= "Select2" style= "width:100px;height:160px"; >
<option value= "8" > Option 8</option>
</select>
<div>
<span id= "Remove" ><< select Remove to left </span>
<span id= "Remove_all" ><< all deleted to left </span>
</div>
</div>
</body>
Note that the Multiple property of the Select has only been added before multiple select options appear in the Select box.
Otherwise, only one will be displayed.
jquery Code parsing:
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
Move to the right.
$ (' #add '). Click (function () {
Get the selected option, delete and append to each other
$ (' #select1 option:selected '). Appendto (' #select2 ');
});
Move to left
$ (' #remove '). Click (function () {
$ (' #select2 option:selected '). Appendto (' #select1 ');
});
Move all to the right.
$ (' #add_all '). Click (function () {
Get all the options, delete and append to each other
$ (' #select1 option '). Appendto (' #select2 ');
});
Move all to the left.
$ (' #remove_all '). Click (function () {
$ (' #select2 option '). Appendto (' #select1 ');
});
Double-click Options
$ (' #select1 '). DblClick (function () {//Bind double-click event
Get all the options, delete and append to each other
$ ("option:selected", this). Appendto (' #select2 '); Append to each other
});
Double-click Options
$ (' #select2 '). DblClick (function () {
$ ("option:selected", this). Appendto (' #select1 ');
});
});
</script>
Here's to noteis $ ("option:selected", this). This looks a little strange. In fact $ () has 2 parameters, one is selector, one is scope. To be distinguished from $ ("xxxx,xxx"). The common meaning of $ (' xxxx ') is actually the default of the second scope. Full said should be $ (' xxxx ', document). Once this is added, the scope is limited to #select1 or #select2. That is, the selected item in Select1 is added to the back of the #select2.
The effect is similar to $ ("#select1 option:selected").
If you do not add, this parameter will be involved in the global selection. Will go wrong.
Note Point 2:
The difference between the append () and the Appendto () method.
Append (CONTENT|FN) appends content to each matching element.
Appendto (content) appends all matching elements to another specified set of element elements.
The former is to add content to the matching element, which appends the matched element to another specified set of elements.
such as $ ("P"). Append ("<b>Hello</b>"); Append content <b>Hello</b> to P element.
Original P element content: <p>i would like to say: </p> now P element content: [<p>i would like to say: <b>hello</b></p& Gt ]$ ("P"). Appendto ("div"); append the P element to the DIV element. Original content: <p>i would like to say: </p>
<div></div><div></div> results: <div><p>i would like to say: </p></div> <div><p>i would like to say: </p></div>