JavaScript 做的挑選介面

來源:互聯網
上載者:User

非常簡單,不止內容簡單,頁面也很簡單,

沒有在 Code-Behind 寫任何東西,純粹的 JavaScript ,

需要提點的是 ListBox 控制項在瀏覽器中會轉譯為 Select 表單對象,

該題就是依據這個來實現的

直接看標籤吧

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            height: 42px;
            text-align: center;
        }
        #btnToRight
        {
        }
        .style2
        {
            height: 8px;
        }
    </style>

    <script language="javascript" type="text/javascript">
// <!CDATA[

        function btnToRight_onclick() {
            var arraylboxSource = new Array();
            var arraylboxTarget = new Array();
            var lboxSource = document.getElementById('<%=lboxSource.ClientID %>');
            var lboxTarget = document.getElementById('<%=lboxTarget.ClientID %>');
            for (var i = 0; i < lboxTarget.options.length; i++) {
                arraylboxTarget[i] = lboxTarget.options[i];
            }
            var countTarget = 0;
            var countSource = 0;
            for (var i = 0; i < lboxSource.options.length; i++) {
                if (lboxSource.options[i].selected && lboxSource.options[i].value != " ") {
                    arraylboxTarget[lboxTarget.length + countTarget] = lboxSource.options[i];
                    countTarget++;
                }
                else {
                    arraylboxSource[countSource] = lboxSource.options[i];
                    countSource++;
                }
            }
            lboxSource.length = 0;
            lboxTarget.length = 0;
            for (var i = 0; i < arraylboxSource.length; i++) {
                lboxSource[i] = arraylboxSource[i];
            }
            for (var i = 0; i < arraylboxTarget.length; i++) {
                lboxTarget[i] = arraylboxTarget[i];
            }
        }

        function btnToLeft_onclick() {
            var arraylboxSource = new Array();
            var arraylboxTarget = new Array();
            var lboxSource = document.getElementById('<%=lboxTarget.ClientID %>');
            var lboxTarget = document.getElementById('<%=lboxSource.ClientID %>');
            for (var i = 0; i < lboxTarget.options.length; i++) {
                arraylboxTarget[i] = lboxTarget.options[i];
            }
            var countTarget = 0;
            var countSource = 0;
            for (var i = 0; i < lboxSource.options.length; i++) {
                if (lboxSource.options[i].selected && lboxSource.options[i].value != " ") {
                    arraylboxTarget[lboxTarget.length + countTarget] = lboxSource.options[i];
                    countTarget++;
                }
                else {
                    arraylboxSource[countSource] = lboxSource.options[i];
                    countSource++;
                }
            }
            lboxSource.length = 0;
            lboxTarget.length = 0;
            for (var i = 0; i < arraylboxSource.length; i++) {
                lboxSource[i] = arraylboxSource[i];
            }
            for (var i = 0; i < arraylboxTarget.length; i++) {
                lboxTarget[i] = arraylboxTarget[i];
            }
        }

// ]]>
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table style="width: 100%;">
        <tr>
            <td rowspan="3" style="text-align: right">
                <asp:ListBox ID="lboxSource" runat="server" Height="150px" Width="200px"
                     SelectionMode="Multiple">
                    <asp:ListItem>今天是個好日子,是星期一</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期二</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期三</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期四</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期五</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期六</asp:ListItem>
                    <asp:ListItem>今天是個好日子,是星期天</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期一</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期二</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期三</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期四</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期五</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期六</asp:ListItem>
                    <asp:ListItem>今天是個壞日子,是星期天</asp:ListItem>
                </asp:ListBox>
            </td>
            <td class="style1">
                <input id="btnToRight" type="button" value="&gt;&gt;"
                       onclick="return btnToRight_onclick()" />
            </td>
            <td rowspan="3" style="text-align: left">
                <asp:ListBox ID="lboxTarget" runat="server" Height="150px"
                     Width="200px" SelectionMode="Multiple">
                </asp:ListBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
            </td>
        </tr>
        <tr>
            <td style="text-align: center">
                <input id="btnToLeft" type="button" value="&lt;&lt;"
                       onclick="return btnToLeft_onclick()" />
            </td>
        </tr>
    </table>
    <div>
    </div>
    </form>
</body>
</html>

結果如下

單擊向右的按鈕後

再單擊向左的按鈕後

以上就是整個對挑選介面的一個實現,非常簡單吧

                                                   2010—1 –24

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.