Implementation Code for mutual adjustment of two ListBox subitems Based on JQUERY

Source: Internet
Author: User

HTML:
Copy codeThe Code is as follows:
<Div id = "divObj3" class = "divContent">
<Input id = "hidColorSelect" name = "ColorSelect" type = "hidden" value = "3, 5, 6, 11, 12, 13, 14"/>
<Table style = "width: 100%; text-align: center;">
<Tr class = "tr">
<Td class = "tdr" align = "center" width = "50%">
<Span id = "ctl00_contentplaceholder=webpanel4_label7"> NO color selected </span>:
</Td>
<Td class = "tdl" width = "1%">
</Td>
<Td class = "tdr" align = "center" width = "50%">
<Span id = "ctl00_contentplaceholder=webpanel4_label8"> selected color </span>:
</Td>
</Tr>
<Tr class = "tr">
<Td align = "right">
<Select id = "colorUnSelect" multiple = "multiple" name = "unSelectColors" ondblclick = "listMove ('colorselect', 'colorunselect', 'hidcolorselect', true, this. selectedIndex) "size =" 8 "style =" height: 200px; width: 90%; "> <option value =" 4 "> blue </option>
<Option value = "21"> Red 132 </option>
</Select>
</Td>
<Td>


</Td>
<Td align = "left">
<Select id = "colorSelect" multiple = "multiple" name = "selectColors"
Ondblclick = "listMove ('colorselect', 'colorunselect', 'hidcolorselect', false, this. selectedIndex )"
Size = "8" style = "height: 200px; width: 90%;">
<Option value = "3"> Red </option>
<Option value = "5"> purple </option>
<Option value = "6"> yellow </option>
<Option value = "11"> black </option>
<Option value = "12"> White </option>
<Option value = "13"> green </option>
<Option value = "14"> Pink </option>
</Select>
</Td>
</Tr>
</Table>
</Div>

Corresponding JS method:
Copy codeThe 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 ("<option value = '" + $ (this ). val () + "'>" + $ (this ). text () + "</option> ");
$ (This). remove ();
});
}
Else {
Source. find ("option: selected"). each (function (){
$ (This). remove ();
Distinct. append ("<option value = '" + $ (this ). val () + "'>" + $ (this ). text () + "</option> ");
});
}
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.