Implementation Code for mutual adjustment of two ListBox subitems Based on JQUERY _ jquery-js tutorial

Source: Internet
Author: User
JQUERY-based implementation code for mutual adjustment of two ListBox subitems. For more information, see. HTML:

The Code is as follows:
















Color not selected:


Selected color:

Blue Red 132




Ondblclick = "listMove ('colorselect', 'colorunselect', 'hidcolorselect', false, this. selectedIndex )"Size = "8" style = "height: 200px; width: 90%;">Red Purple Yellow Black White Green Pink



Corresponding JS method:

The Code is as follows:


Function listMove (main, follow, hidetextbox, isBack, index ){
If (index <0)
Return;
Var o = undefined;
Var source;
Var distinct;
Var dddd;
If (! IsBack ){
// A bug exists in IE6 using getElementById
Source = $ ('#' + main); // your own Doc ument. getElementById (main );
Distinct = $ ('#' + follow); // specify your doc ument. getElementById (follow );
}
Else {
Source = $ ('#' + follow); // specify your doc ument. getElementById (follow );
Distinct = $ ('#' + main); // specify your doc ument. getElementById (main );
}
Var hid = $ ('#' + hidetextbox) [0]; // document. getElementById (hidetextbox );
If (index! = Undefined ){
Var op = "option: eq (" + index + ")";
Source. find (op). each (function (){
Distinct. append (""+ $ (This). text () +"");
$ (This). remove ();
});
}
Else {
Source. find ("option: selected"). each (function (){
$ (This). remove ();
Distinct. append (""+ $ (This). text () +"");
});
}
Var str = "";
// Traverse Listbox to obtain the value of the selected item
$ ('#' + Main + 'option'). each (function (){
Str + = $ (this). val () + ',';
});
Hid. value = str;
}

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.