js实现全选与反选

时间:2022-02-02 09:38:14

 

<script type="text/javascript">
function ckbCheckAll() {
var ckbAll = document.getElementsByName("checkone");
//alert(ckbAll.length);
var ckbMarkAll = document.getElementById("all");
var intIndex = 0;
for (intIndex = 0; intIndex < ckbAll.length; intIndex++) {
if (ckbMarkAll.checked) {
ckbAll[intIndex].checked = true;
}
else {
ckbAll[intIndex].checked = false;
}
}
}
</script>
<table cellpadding="1" cellspacing="1" style="width:500px; background:#cccccc;" >        <tr style="background-color:#ffffff">            <th><input type="checkbox" onclick="ckbCheckAll()" id="all" /></th>            <th style="width:100px">序列号</th>            <th style="width:250px">标题</th>            <th style="width:100px">时间</th>        </tr>            <asp:Repeater ID="rptinfo" runat="server">                <ItemTemplate>                   <tr  style="background-color:#ffffff">                        <td align="center"><input type="checkbox" name="checkone"/></td>                        <td align="center"><%#Eval("id") %></td>                        <td align="center"><%#Eval("Title") %></td>                        <td align="center"><%#Eval("senddate","{0:yyyy-MM-dd}") %></td>                   </tr>                </ItemTemplate>            </asp:Repeater></table>


如果想在后台获取选中项就接着看下去

string sss = Request.Form["checkone"];
Response.Write(sss);

 

当然,你需要在ispostback那里判断是否是第一次加载,否则不管你怎么弄都获取不到checkbox的值