免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
js操作CheckBoxList實(shí)現(xiàn)全選、反選 -教育技術(shù)-乳山市教育網(wǎng)

js操作CheckBoxList實(shí)現(xiàn)全選、反選

錄入時(shí)間:2009-05-27 10:35:13  作者:教育技術(shù)管理員  瀏覽次數(shù):1127  文字大?。骸?a href="javascript:fontZoom(16)">大】【】【
來(lái)源:乳山市教育網(wǎng)
對(duì)于CheckBoxList控件來(lái)說(shuō),一方面要實(shí)現(xiàn)大量數(shù)據(jù)在服務(wù)器端的綁定工作,另一方面往往要求實(shí)現(xiàn)全

選、反選等功能。雖然可以在服務(wù)器端完成這方面的工作,但這樣一個(gè)簡(jiǎn)單的工作似乎更應(yīng)該在客戶端完

成。

       具體方法:

       在頁(yè)面中放入一個(gè)CheckBoxList控件,并添加幾項(xiàng),用來(lái)分析其產(chǎn)生的HTML代碼,這樣在使用js進(jìn)行

動(dòng)態(tài)控制時(shí),將會(huì)非常清晰其測(cè)試代碼如下所示:

       <asp:CheckBoxList ID="CheckBoxList1" runat="server" CellPadding="3" CellSpacing="3"

            RepeatColumns="3">

            <asp:ListItem>1232</asp:ListItem>

            <asp:ListItem>254</asp:ListItem>

            <asp:ListItem Value="5643">5643</asp:ListItem>

            <asp:ListItem>789</asp:ListItem>

            <asp:ListItem>654</asp:ListItem>

            <asp:ListItem>564</asp:ListItem>

            <asp:ListItem>8564</asp:ListItem>

            <asp:ListItem>8564</asp:ListItem>

            <asp:ListItem>5452</asp:ListItem>

            <asp:ListItem>5641</asp:ListItem>

        </asp:CheckBoxList>

    在瀏覽器中查看,并對(duì)Html進(jìn)行分析:以下是DropDownList控件生成的HTML代碼。

<table id="CheckBoxList1" cellspacing="3" cellpadding="3" border="0">
         <tr>
            <td>
<input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" /><label for="CheckBoxList1_0">1232</label>

           </td>

           <td><input id="CheckBoxList1_4" type="checkbox" name="CheckBoxList1$4" /><label for="CheckBoxList1_4">654</label>

          </td>

.......

</table>

     在這里,節(jié)選了部分代碼,其中藍(lán)色部分是我們關(guān)心的。在HTML中CheckBoxList生成了

許多input(type為checkbox),并且其ID為“CheckBoxList1_i”(i為數(shù)字)。這樣我們只

需要知道一共有幾項(xiàng)就可以輕松的實(shí)現(xiàn)js對(duì)它的控制。

     這些input都包含在一個(gè)id為CheckBoxList1的table中,因此可以通過(guò):

document.getElementById("CheckBoxList1").getElementsByTagName("input").length

這一方法獲取CheckBoxList一共有多少項(xiàng),剩下的工作其實(shí)就很簡(jiǎn)單了,通過(guò)js更改每一個(gè)

checkbox的狀態(tài)即可。先添加三個(gè)button,用來(lái)實(shí)現(xiàn)全選、反選及清除控制,如下所示:

          <input type="button" on click="checkAll()" value="check All" />

        <input type="button" on click="ReverseAll()" value="Reverse All" id="Button1" />   

        <input type="button" on click="deleteAll()" value="delete All" />

     添加全選、反選及清除函數(shù)如下:

     function checkAll(){

//            alert(document.getElementById("CheckBoxList1").getElementsByTagName("input").length);

            for(var i=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)

            {

                document.getElementById("CheckBoxList1_"+i).checked=true;

            }            

        }

        function deleteAll(){

            for(var i=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)

             {

                document.getElementById("CheckBoxList1_"+i).checked = false;

            }

        }

        function ReverseAll(){

            for(var i=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)

             {

                var objCheck = document.getElementById("CheckBoxList1_"+i);

                if(objCheck.checked)

                    objCheck.checked = false;

                else

                    objCheck.checked = true;

            }

        }

    OK,現(xiàn)在通過(guò)IE測(cè)試,綁定工作可以在后臺(tái),全選等輔助功能可以自由發(fā)揮了!?。?/span>

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
GridView中CheckBox客戶端全選
CheckBoxList - 盼君的日志 - 網(wǎng)易博客
Wizard控件的使用
ASP.NET?服務(wù)器控件對(duì)應(yīng)HTML標(biāo)簽
ListBox基本功能使用方法
webform復(fù)合控件以及用來(lái)做年月日選擇日期的DropDownList控件
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服