乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

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

       suweixin 2011-01-15

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

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

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

      成。

             具體方法:

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

      動態(tài)控制時,將會非常清晰其測試代碼如下所示:

             <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>

          在瀏覽器中查看,并對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àn)js對它的控制。

           這些input都包含在一個id為CheckBoxList1的table中,因此可以通過:

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

      這一方法獲取CheckBoxList一共有多少項,剩下的工作其實就很簡單了,通過js更改每一個

      checkbox的狀態(tài)即可。先添加三個button,用來實現(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)在通過IE測試,綁定工作可以在后臺,全選等輔助功能可以自由發(fā)揮了?。?!

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多