• 全选特效并修改checkbox样式


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>全选</title>
        <style>
            #myCheck1 + label{
                background-color: white;
        border-radius: 5px;
        border:1px solid #dbdbdb;
        width:20px;
        height:20px;
        display: inline-block;
        text-align: center;
        vertical-align: text-top;
        margin-left: -22px;
        line-height: 20px;
            }
        #myCheck1:checked + label:after{
                content: "2714";
        color: #8bbd26;
        border: 1px solid #8bbd26;
        background-color: white;
        border-radius: 5px;
        width: 20px;
        height: 20px;
        display: inline-block;
        text-align: center;
        margin-left: -1px;
        line-height: 20px;
            }
        </style>
    </head>
    <body>
        全选<input type="checkbox" id="myCheck1">
        <label for="myCheck1"></label>
        <div id="list">
            <input type="checkbox" name="" value=""><span>选项一</span>
            <input type="checkbox" name="" value=""><span>选项二</span>
            <input type="checkbox" name="" value=""><span>选项三</span>
            <input type="checkbox" name="" value=""><span>选项四</span>    
        </div>
    </body>
    <script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script>
              var all = document.getElementById("myCheck1");
                 var tbody = document.getElementById("list");
                 var checkboxs = tbody.getElementsByTagName("input");
                 all.onclick = function() {
                     for (var i = 0; i < checkboxs.length; i++) {
                         var checkbox = checkboxs[i];
                         checkbox.checked = this.checked;
                     }
                     
                 };
                 for (var i = 0; i < checkboxs.length; i++) {
                     checkboxs[i].onclick = function() {
                         var isCheckedAll = true;
                         for (var i = 0; i < checkboxs.length; i++) {
                             if (!checkboxs[i].checked) {
                                 isCheckedAll = false;
                                 break;
                             }
                         }
                         all.checked = isCheckedAll;
                     };
                 }
    
          
    </script>
    </html>
  • 相关阅读:
    Ajax的工作原理
    ios 应用多语言自由切换实现
    开源码应用之Eclipse篇
    搜索引擎solr和elasticsearch
    字符串截取进阶
    nginx源代码分析--nginx模块解析
    C#网络编程系列文章(五)之Socket实现异步UDPserver
    mysql存储引擎的种类与差别(innodb与myisam)
    程序的记事本--log4net
    在海思hisiv100nptl平台上交叉编译并安装SRS
  • 原文地址:https://www.cnblogs.com/jinsuo/p/9415422.html
Copyright © 2020-2023  润新知