zoukankan      html  css  js  c++  java
  • js 树 没用的树,法克

    <!DOCTYPE html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>树形菜单示例</title>
    <style type="text/css">
    ul>li{
    list-style: none;
    }
    /* 可展开*/
    .switch-open
    {
    margin-left:-12px;
    border:6px solid transparent;
    display:inline-block;
    0px;
    height:0px;
    border-top-color: black;

    }
    /* 展开完毕*/
    .switch-close
    {
    margin-left:-12px;
    border:6px solid transparent;
    display:inline-block;
    0px;
    height:0px;
    border-left-color: black;
    margin-bottom: 2px;

    }
    /* 改变CheckBox样式*/
    input[type='checkbox']{
    20px;
    height: 20px;

    -webkit-appearance:none;
    -moz-appearance: none;
    border: 1px solid #c9c9c9;
    border-radius: 3px;
    outline: none;
    color:white;
    text-align: center;
    }
    input[type='checkbox']:before
    {
    content: '√ ';
    color:transparent;
    }
    input[type=checkbox]:checked{
    background-color: #30add6;
    }
    input[type=checkbox]:checked:before{
    content: '√';
    color:white;
    font-weight: bold;
    }

    </style>
    </head>
    <body>
    <div class="warp">
    <ul id="container">
    </ul>
    </div>


    <script type="text/javascript">

    //结构
    var json={
    '0-0':{
    '0-0-0':null,
    '0-0-1':{
    '0-0-1-0':null,
    '0-0-1-1':null,
    '0-0-1-2':null
    },
    '0-0-2':null
    },
    '0-1':{
    '0-1-0':null,
    '0-1-1':null
    },
    '0-2':null
    };

    //这里生成DOM
    function generate(json,par)
    {
    for(var attr in json)
    {
    var ele=document.createElement('li');
    if(!json[attr])
    ele.innerHTML=' <input type="checkbox"></input>'+attr;
    else
    {
    ele.innerHTML='<span><span class="switch-open" onclick="toggle(this)"></span><input type="checkbox" onclick="checkChange(this)"></input>'+attr+'</span>';
    var nextpar=document.createElement('ul');
    ele.appendChild(nextpar);
    generate(json[attr],nextpar);
    }
    par.appendChild(ele);
    }
    }
    generate(json,document.getElementById('container'));

    //处理展开和收起
    function toggle(eve)
    {
    var par=eve.parentNode.nextElementSibling;
    if(par.style.display=='none')
    {
    par.style.display='block';
    eve.className='switch-open';

    }
    else
    {
    par.style.display='none';
    eve.className='switch-close';
    }
    }

    //处理全部勾选和全部不选
    function checkChange(eve)
    {
    var oul=eve.parentNode.nextElementSibling;
    if(eve.checked)
    {
    for(var i=0;i<oul.querySelectorAll('input').length;i++)
    {
    oul.querySelectorAll('input')[i].checked=true;
    }
    }
    else
    {
    for(var i=0;i<oul.querySelectorAll('input').length;i++)
    {
    oul.querySelectorAll('input')[i].checked=false;
    }
    }
    }
    </script>



    </body>
    </html>

  • 相关阅读:
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    deep-in-es6(二)
    jQuery插件--根据数据加载的进度动画案例
    shop--14.升级--本地账号注册,登录,修改密码
    shop--13.升级--Redis缓存技术
    JedisUtil工具类
    shop--12.升级--加密数据库明文密码
    shop--11.阿里云部署java网站与微信开发调试
    shop--10.店铺详情(后台+前端类似于shoplist)
    shop--10.店铺列表(前端)
  • 原文地址:https://www.cnblogs.com/ayanboke/p/11534529.html
Copyright © 2011-2022 走看看