/**
*
* 移動select的部分內容,必須存在value,此函數以value爲標準進行移動
*
* oSourceSel: 源列表框對象
* oTargetSel: 目的列表框對象
* oCountSel: 要進行組合成字符串的列表框
* oTargetTb: 組合字符串後放置的textbox
*/
function moveSelected(oSourceSel,oTargetSel,oCountSel,oTargetTb)
{
//alert(oSourceSel.id+oTargetSel.id+oCountSel.id+oTargetTb.id);
//建立存儲value和text的緩存數組
var arrSelValue = new Array();
var arrSelText = new Array();
//此數組存貯選中的options,以value來對應
var arrValueTextRelation = new Array();
var index = 0;//用來輔助建立緩存數組
//存儲源列表框中所有的數據到緩存中,並建立value和選中option的對應關係
for(var i=0; i<oSourceSel.options.length; i++)
{
if(oSourceSel.options[i].selected)
{
//存儲
arrSelValue[index] = oSourceSel.options[i].value;
arrSelText[index] = oSourceSel.options[i].text;
//建立value和選中option的對應關係
arrValueTextRelation[arrSelValue[index]] = oSourceSel.options[i];
index ++;
}
}
//增加緩存的數據到目的列表框中,並刪除源列表框中的對應項
for(var i=0; i<arrSelText.length; i++)
{
//增加
var oOption = document.createElement("option");
oOption.text = arrSelText[i];
oOption.value = arrSelValue[i];
oTargetSel.add(oOption);
//刪除源列表框中的對應項
oSourceSel.removeChild(arrValueTextRelation[arrSelValue[i]]);
}
var str = "";
//把所有目的選擇框裏的內容以“;”分割放在textbox中
for(var i=0; i<oCountSel.options.length; i++)
{
str += oCountSel.options[i].value + "-" +oCountSel.options[i].text +";";
}
oTargetTb.value = str.substr(0,str.length-1);
}
</script>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<asp:ListBox ID="lbProduct" runat="server" Height="227px" Width="149px" ondblclick="moveSelected($('WzdSelector_lbProduct'),
$('WzdSelector_lbSelect'),
$('WzdSelector_lbSelect'),
$('WzdSelector_txtselect'))"></asp:ListBox></td>
<td>
<input id="Button1" type="button" value=">" onclick="moveSelected($('<%=lbProduct.ClientID %>'),
$('<%=lbSelect.ClientID%>'),
$('<%=lbSelect.ClientID%>'),
$('<%=txtselect.ClientID%>'))"
style="width: 51px" />
<br />
<input style="width: 51px" id="Button2" type="button" value="<" onclick="moveSelected($('<%=lbSelect.ClientID%>'),
$('<%=lbProduct.ClientID %>'),
$('<%=lbSelect.ClientID%>'),
$('<%=txtselect.ClientID%>'))" />
</td>
<td>
<asp:ListBox ID="lbSelect" runat="server" Height="227px" Width="149px" ondblclick="moveSelected($('WzdSelector_lbSelect'),
$('WzdSelector_lbProduct'),
$('WzdSelector_lbSelect'),
$('WzdSelector_txtselect'))">
</asp:ListBox>
<input id="txtselect" type="hidden" runat="server" />
</td>
</tr>
</table>