• 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)" />全选/取消
  • 相关阅读:
    ssm整合用到的依赖jar包(不充足)
    eclipse中Maven web项目的目录结构浅析
    何时使用抽象类?何时使用接口?
    $().attr() 和 $().css的区别
    AJAX防重复提交的办法总结
    CentOS 8 扩展LVM,更改xfs卷报错解决方法
    安装Minikube无法访问k8s.gcr.io的简单解决办法
    Windows 10、Ubuntu 18.04 双系统 双硬盘 安装经验总结
    转眼十年
    Dresdon二次开发
  • 原文地址:https://www.cnblogs.com/haoxr/p/3032981.html
Copyright © 2020-2023  润新知