实现从一个ListBox向另一个ListBox中移动选中项,并按照value进行排序

实现从一个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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值