Jquery implements the effect of the list box

Source: Internet
Author: User







In java web development, list boxes are often used, especially in system permission management, as shown in. To achieve the above effect, see the following source code:
The source code is as follows:
<Html>
<Head>
<Title> select all results </title>
<Script src = "jquery. js"> </script>
</Head>
<Body background = "3.png">
<Div id = "left" style = "float: left; width: 200px">
<Select onDblClick = "moveright ()" id = "list1" size = "10" style = "width: 150px"> // The data here can be changed to dynamic
<Option id = "1"> Item 1 </option>
<Option id = "2"> option 2 </option>
<Option> Item 3 </option>
<Option> Item 1 </option>
<Option> option 2 </option>
<Option> Item 3 </option>
<Option> Item 4 </option>
<Option> Item 5 </option>
<Option> Item 6 </option>
<Option> Item 7 </option>
<Option> Item 8 </option>
<Option> Item 9 </option>
<Option> Item 10 </option>
</Select>
</Div>
<Div id = "right" style = "float: left">
<Select onDblClick = "moveleft ()" size = "10" id = "list2" style = "width: 150px">
</Select>
</Div>
// Note that the script must be written in the body. Otherwise, an error will be reported.
<Script>
Var L = $ ("# list1 ");
Var R = $ ("# list2 ");
Function moveleft (){
Var move = new Array ();
$ ("# List2> option: selected"). each (function (){
Var a1 = $ (this );
Var a1 _ = (this).html ();
Var a2 = $ ("# list1> option ");
Var a2 _ = $ ("# list1> option" pai.html ();
If (a2 _ = null ){
$ (This). remove (). appendTo (L); // move to the left when the left side is empty.
} Else {
A2.each (function (){
If(((this).html () = a1 _){
Move. push (a1 _);
} Else {

}
});
If (move [0] = a1 _){
A1.remove ();
} Else {
A1.remove (). appendTo (L );
}
};
});
}
Function moveright (){
Var move = new Array ();
$ ("# List1> option: selected"). each (function (){
Var a1 = $ (this );
Var a1 _ = (this).html ();
Var a2 = $ ("# list2> option ");
Var a2 _ = $ ("# list2> option" pai.html ();
If (a2 _ = null ){
$ (This). remove (). appendTo (R );
} Else {
A2.each (function (){
If(((this).html () = a1 _){
Move. push (a1 _);
} Else {

}
});
If (move [0] = a1 _){
 
} Else {
A1.remove (). appendTo (R );
}
};
 
});
}
</Script>
</Body>
</Html>

 

 

From pursuit-Column

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.