利用javascript实现复选框的全选功能

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm43.aspx.cs" Inherits="ASP.NETWebControlDaQuan.WebForm43" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        //利用javascript实现复选框的全选功能
        function allSelect() {
            var v1 = document.getElementById("selectAll");
            var v2 = document.getElementsByName("select");
            for (var i = 0; i < v2.length; i++) {
                v2[i].checked = v1.checked;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gv" runat="server" DataSourceID="studentDataSource" AllowPaging="true">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <input type="checkbox" id="selectAll" onclick="allSelect()" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <input type="checkbox" name="select" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="studentDataSource" runat="server" ConnectionString="server=(local);database=db_students;integrated security=true" SelectCommand="select top 100 * from CwwTest">
            </asp:SqlDataSource>
        </div>
    </form>
</body>
</html>

阅读更多
想对作者说点什么? 我来说一句

javaScript全选

2010年12月01日 1KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭