zoukankan      html  css  js  c++  java
  • javascript Check All, Uncheck All and check one at least

    Use javascript to checked all,uncheck all and check if one item at least been checked when deleting.

    代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!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>JSRepeaterCheckBox</title>
    <script language="javascript">
    function CheckCount() {
    var checks = document.getElementsByTagName('input');
    for (var i = 0; i < checks.length; i++) {
    if (checks[i].type == 'checkbox') {
    if (checks[i].checked == true) {
    return true;
    }
    }
    }
    alert(
    'Please select one item at list!');
    return false;
    }

    function CheckAll() {
    var checks = document.getElementsByTagName('input');
    var checkAllObject = document.getElementById('checkAllItem');
    var status = checkAllObject.checked;
    for (var i = 0; i < checks.length; i++) {
    if (checks[i].type == 'checkbox') {
    checks[i].checked
    = status;
    }
    }
    // return true;
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="rptAppliant" runat="server" DataSourceID="SqlDataSource1" >
    <HeaderTemplate>
    <table>
    <th>ID</th><th>Name</th><th><input type="checkbox" id="checkAllItem" name="checkAll" onclick="CheckAll()" /></th>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td><%#Eval("id") %></td>
    <td ><%#Eval("Name") %></td>
    <td><asp:CheckBox runat="server" ID="ckb" /></td>
    </tr>
    </ItemTemplate>
    <FooterTemplate></table></FooterTemplate>
    </asp:Repeater>
    <div><asp:Button runat="server" Text="Delete" OnClientClick="return CheckCount();" /></div>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString
    ="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand
    ="SELECT * FROM [Appliant]"></asp:SqlDataSource>
    </form>
    </body>
    </html>

    The target html generated by iis is as blow:

    代码


    <!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><title>
    JSRepeaterCheckBox
    </title>
    <script language="javascript">
    function CheckCount() {
    var checks = document.getElementsByTagName('input');
    for (var i = 0; i < checks.length; i++) {
    if (checks[i].type == 'checkbox') {
    if (checks[i].checked == true) {
    return true;
    }
    }
    }
    alert(
    'Please select one item at list!');
    return false;
    }

    function CheckAll() {
    var checks = document.getElementsByTagName('input');
    var checkAllObject = document.getElementById('checkAllItem');
    var status = checkAllObject.checked;
    for (var i = 0; i < checks.length; i++) {
    if (checks[i].type == 'checkbox') {
    checks[i].checked
    = status;
    }
    }
    // return true;
    }
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExNjU5ODUwMzYPZBYCAgMPZBYCAgEPFgIeC18hSXRlbUNvdW50AgYWDAIBD2QWAmYPFQIBMQlXYXNoaW50b25kAgIPZBYCZg8VAgEyBEJ1c2hkAgMPZBYCZg8VAgEzBUxhbmN5ZAIED2QWAmYPFQIBNAdHb2xkbWFuZAIFD2QWAmYPFQIBNQNKaW1kAgYPZBYCZg8VAgE2BEthdGVkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYGBRVycHRBcHBsaWFudCRjdGwwMSRja2IFFXJwdEFwcGxpYW50JGN0bDAyJGNrYgUVcnB0QXBwbGlhbnQkY3RsMDMkY2tiBRVycHRBcHBsaWFudCRjdGwwNCRja2IFFXJwdEFwcGxpYW50JGN0bDA1JGNrYgUVcnB0QXBwbGlhbnQkY3RsMDYkY2tibHrakvFGc4n+fTnFVQMpA2tStXo=" />
    </div>

    <div>

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCAKcs6y5BALn1abPBgLE1KbPBgKh1qbPBgL+1KbPBgLj1KbPBgLA06bPBgKfwImNCx8u9urjhh+8kC/RRzFaRFN/1r3G" />
    </div>
    <div>

    <table>
    <th>ID</th><th>Name</th><th><input type="checkbox" id="checkAllItem" name="checkAll" onclick="CheckAll()" /></th>

    <tr>
    <td>1</td>
    <td >Washinton</td>
    <td><input id="rptAppliant_ctl01_ckb" type="checkbox" name="rptAppliant$ctl01$ckb" /></td>
    </tr>

    <tr>
    <td>2</td>
    <td >Bush</td>
    <td><input id="rptAppliant_ctl02_ckb" type="checkbox" name="rptAppliant$ctl02$ckb" /></td>
    </tr>

    <tr>
    <td>3</td>
    <td >Lancy</td>
    <td><input id="rptAppliant_ctl03_ckb" type="checkbox" name="rptAppliant$ctl03$ckb" /></td>
    </tr>

    <tr>
    <td>4</td>
    <td >Goldman</td>
    <td><input id="rptAppliant_ctl04_ckb" type="checkbox" name="rptAppliant$ctl04$ckb" /></td>
    </tr>

    <tr>
    <td>5</td>
    <td >Jim</td>
    <td><input id="rptAppliant_ctl05_ckb" type="checkbox" name="rptAppliant$ctl05$ckb" /></td>
    </tr>

    <tr>
    <td>6</td>
    <td >Kate</td>
    <td><input id="rptAppliant_ctl06_ckb" type="checkbox" name="rptAppliant$ctl06$ckb" /></td>
    </tr>
    </table>
    <div><input type="submit" name="ctl02" value="Delete" onclick="return CheckCount();" /></div>
    </div>

    </form>
    </body>
    </html>
  • 相关阅读:
    19 个必须知道的 Visual Studio 快捷键
    面试感悟:一名3年工作经验的程序员应该具备的技能
    来自开发者技术前线 高级程序员,你需要养成这7个习惯
    来自极客头条的 15个常用的javaScript正则表达式
    来自极客头条的 35 个 Java 代码性能优化总结
    [Visual studio] Visual studio 2017添加引用时报错未能正确加载ReferenceManagerPackage包的解决方法
    [Visual Studio] 未能完成操作 不支持此接口
    未能加载文件或程序集“Benlai.SOA.Framework.Common, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。
    [Visual Studio] NuGet发布自定义包(Library Package)
    未能加载视图状态。正在向其中加载视图状态的控件树必须与前一请求期间用于保存视图状态的控件树相匹配。例如,当以动态方式添加控件时,在回发期间添加的控件必须与在初始请求期间添加的控件的类型和位置相匹配
  • 原文地址:https://www.cnblogs.com/philzhou/p/1793554.html
Copyright © 2011-2022 走看看