实现从一个ListBox向另一个ListBox中移动选中项,并按照value进行排序
只是双击进行移动。
适合于IE和Firefox,其它没试过,呵呵。
<script language="javascript" type="text/javascript">
function MoveOne(listSrc, listDest) {
var option = document.createElement('option');
var nIndex = listSrc.selectedIndex;
var value = listSrc.options[nIndex].value;
var nLen;
if (nIndex == -1)
return;
option.appendChild(document.createTextNode(listSrc.options[nIndex].text));
option.setAttribute("value", value);
nLen = listDest.length;
for (var i = 0; i < nLen; i++) {
if (parseInt(listDest.options[i].value) > parseInt(value))
break;
}
if (i == nLen)
listDest.appendChild(option);
else
listDest.insertBefore(option, listDest.options[i]);
listSrc.remove(nIndex);
}
function B_AddOne_onclick() {
MoveOne(document.getElementById("<%=LB_Src.ClientID%>"), document.getElementById("<%=LB_Dest.ClientID%>"));
}
function B_RemoveOne_onclick() {
MoveOne(document.getElementById("<%=LB_Dest.ClientID%>"), document.getElementById("<%=LB_Src.ClientID%>"));
}
</script>
aspx中ListBox设置:
<asp:ListBox ID="LB_Src" runat="server" Height="300px" Width="200px" onDblClick="B_AddOne_onclick()">
<asp:ListItem Value="1">List1</asp:ListItem>
<asp:ListItem Value="2">List2</asp:ListItem>
<asp:ListItem Value="3">List3</asp:ListItem>
<asp:ListItem Value="4">List4</asp:ListItem>
<asp:ListItem Value="5">555555555</asp:ListItem>
<asp:ListItem Value="6">666666666666</asp:ListItem>
<asp:ListItem Value="7">777777777777</asp:ListItem>
<asp:ListItem Value="8">888888888888888</asp:ListItem>
<asp:ListItem Value="9">99999999999</asp:ListItem>
</asp:ListBox>