• checkbox 全选


    1、

    View Code
    function checkSelectedAll(thischeck) {
    for (var i = 0; i < form1.elements.length; i++) {
    var e = form1.elements[i];
    if (e.name == 'id') {
    e.checked=thischeck;
    }
    }
    return false;
    }
    
    <input type="checkbox" id="checkall" onclick="checkSelectedAll(this.checked)" />全选/取消

    2、

    View Code
    <script type="text/javascript">
    var carcount=<%=carCount %>;
    var arrcategory=<%=arrCategory %>;
    var selectedcar=<%=selectedCar %>;
    for (var j=0;j<selectedcar.length;j++)
    {
    for (var i=0;i<carcount;i++){
    $("#selectCar").append(
    '<input type="checkbox" id="Car'+i+'" name="id" value="'+arrcategory[i][1]+'" /> '+arrcategory[i][0]+'<br \>'
    )
    if ($("#Car"+i).val()==selectedcar[j]){
    $("#Car"+i).attr("checked","checked");
    } 
    }
    }
    </script>

    3、CheckBoxList全选(火狐浏览器无效)

    View Code
    <input type="checkbox" id="checkall" onclick="selectAll('cblCarModels')" />全选/取消
    
    <asp:CheckBoxList ID="cblCarModels"  runat="server" />
    
    function selectAll(searchName){
    var aa = document.getElementsByTagName("input");
    for (var i=0; i<aa.length; i++)
    {
    if (aa[i].type=='checkbox'&&aa[i].name.indexOf(searchName)>-1)
    {
    aa[i].checked=event.srcElement.checked;
    }
    }
    }

    后台绑定数据:

    View Code
    protected void Page_Load(object sender, EventArgs e)
    {
    Member member = (Member)SessionManager.Member;
    if (member == null)
    {
    Response.Redirect("Login.aspx");
    return;
    }
    
    if (!IsPostBack)
    {
    cblCarModels.DataSource = DictBusiness.FindAllByCategory(EnmDictCategory.车系);
    cblCarModels.DataTextField = "Value";
    cblCarModels.DataValueField = "Code";
    cblCarModels.RepeatColumns = 2;
    cblCarModels.RepeatDirection = RepeatDirection.Horizontal;
    cblCarModels.DataBind();
    
    foreach (ListItem carModel in cblCarModels.Items) {
    if (checkboxSelect(carModel.Value))
    {
    carModel.Selected = true;
    }
    }
    }
    }

    4\直接全选。

      

    View Code
    function checkSelected(ischecked) {
                var allcheckbox = $(":checkbox");
                allcheckbox.attr("checked", ischecked);
            }
    
    <input type="checkbox" id="checkall" onclick="checkSelected(this.checked)" />全选/取消
  • 相关阅读:
    Telnet远程测试
    数据库笔记
    gcc 链接不到 函数实现, undefined reference to xxx
    usb2ttl 引脚定义
    ip v4 地址中 局域网地址范围
    vdi 磁盘文件转换为 vmdk文件的命令
    tftp 命令使用
    无法通过vnc连接到局域网内的树莓派
    镜像服务网站
    C语言 scanf 输入浮点数的用法
  • 原文地址:https://www.cnblogs.com/haoxr/p/3032981.html
Copyright © 2020-2023  润新知