最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js操作CheckBoxList實(shí)現(xiàn)全選/反選(在客服端完成)

 更新時(shí)間:2013年02月02日 17:14:16   作者:  
對(duì)于CheckBoxList控件來(lái)說(shuō),一方面要實(shí)現(xiàn)大量數(shù)據(jù)在服務(wù)器端的綁定工作,另一方面往往要求實(shí)現(xiàn)全選、反選等功能,接下來(lái)將介紹js操作CheckBoxList實(shí)現(xiàn)全選/反選,感興趣的朋友可以了解下,或許對(duì)你有所幫助
對(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è)試代碼如下所示:
復(fù)制代碼 代碼如下:

<asp:CheckBoxListID="CheckBoxList1"runat="server"CellPadding="3"CellSpacing="3"
RepeatColumns="3">
<asp:ListItem>1232</asp:ListItem>
<asp:ListItem>254</asp:ListItem>
<asp:ListItemValue="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代碼。
復(fù)制代碼 代碼如下:

<tableid="CheckBoxList1"cellspacing="3"cellpadding="3"border="0">
<tr>
<td><inputid="CheckBoxList1_0"type="checkbox"name="CheckBoxList1$0"/><labelfor="CheckBoxList1_0">1232</label>
</td>
<td><inputid="CheckBoxList1_4"type="checkbox"name="CheckBoxList1$4"/><labelfor="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ò):
復(fù)制代碼 代碼如下:

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)全選、反選及清除控制,如下所示:
復(fù)制代碼 代碼如下:

<inputtype="button"onclick="checkAll()"value="checkAll"/>
<inputtype="button"onclick="ReverseAll()"value="ReverseAll"id="Button1"/>
<inputtype="button"onclick="deleteAll()"value="deleteAll"/>

添加全選、反選及清除函數(shù)如下:
復(fù)制代碼 代碼如下:

functioncheckAll(){
//alert(document.getElementById("CheckBoxList1").getElementsByTagName("input").length);
for(vari=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)
{
document.getElementById("CheckBoxList1_"+i).checked=true;
}
}
functiondeleteAll(){
for(vari=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)
{
document.getElementById("CheckBoxList1_"+i).checked=false;
}
}
functionReverseAll(){
for(vari=0;i<document.getElementById("CheckBoxList1").getElementsByTagName("input").length;i++)
{
varobjCheck=document.getElementById("CheckBoxList1_"+i);
if(objCheck.checked)
objCheck.checked=false;
else
objCheck.checked=true;
}
}

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

相關(guān)文章

最新評(píng)論

厦门市| 石屏县| 北票市| 富裕县| 巴中市| 拉孜县| 扶余县| 秦皇岛市| 凤庆县| 囊谦县| 囊谦县| 昌宁县| 苍梧县| 招远市| 务川| 永仁县| 保德县| 黎平县| 瑞昌市| 景东| 温泉县| 泽普县| 即墨市| 保亭| 南丹县| 沽源县| 津市市| 澎湖县| 望江县| 平舆县| 姚安县| 宜章县| 宝兴县| 耿马| 广南县| 荣成市| 青神县| 台江县| 观塘区| 南昌县| 鹤岗市|