zoukankan      html  css  js  c++  java
  • dom 按着shift多选

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    
    <style>
    body { margin: 0; padding: 0; }
    ul { padding: 0; margin: 0; }
    li { list-style: none; }
    a { text-decoration: none; color: #000; display: block; }
    #div1 {  250px; height: 20px; border: 1px solid #fe6601; padding: 5px; line-height:20px; margin: 20px auto 0 auto;}
    #ul1 { margin: 0 auto;  260px; line-height: 20px; border: 1px solid #fe6601; display: none;}
    #ul1 li a { padding: 5px; }
    #ul1 li a:hover { background: #fe6601; color: #fff; }
    </style>
    <script type="text/javascript">
    window.onload = function ()
    {
        var odiv = document.getElementById('div1');
        var oul = document.getElementById('ul1');
        var arr = [];
        
        odiv.onclick = function (ev)
        {
            var ev = ev || event;
            ev.cancelBubble = true;
            oul.style.display = 'block';
        }
        
        for( var i = 0; i < oul.children.length; i++)
        {
            oul.children[i].onclick = function (ev)
            {
                var ev = ev || event;
                if(ev.shiftKey)
                {
                    ev.cancelBubble = 'true';
                }
                
                for(var i = 0; i < arr.length; i++)
                {
                    if(this.children[0].innerHTML == arr[i])
                    {
                        arr.splice(i,1);
                        odiv.innerHTML = arr.join(',');
                        bgcolor();
                        return;
                    }
                }
                arr.push ( this.children[0].innerHTML);
                odiv.innerHTML = arr.join(',');
                bgcolor();
                
                function bgcolor ()
                {
                    for(var i = 0; i < oul.children.length; i++)
                    {
                        oul.children[i].children[0].style.background = '';
                        oul.children[i].children[0].style.color = '';
                    }
                    
                    var arr1 = odiv.innerHTML.split(',');
                    for(var i = 0; i < arr1.length; i++)
                    {
                        for(var j = 0; j < oul.children.length ; j++)
                        {
                            if(oul.children[j].children[0].innerHTML == arr1[i])
                            {
                                oul.children[j].children[0].style.background = '#fe6601';
                                oul.children[j].children[0].style.color = '#fff';
                            }
                        }
                    }
                }
            }
        }
        
        document.onclick = function ()
        {
            oul.style.display = 'none';
            arr = [];
        }
    };
    </script>
    </head>
    
    <body>
        <div id="div1">按住shift多</div>
        <ul id="ul1">
            <li><a href="javascript:;">宋体</a></li>
            <li><a href="javascript:;">黑体</a></li>
            <li><a href="javascript:;">楷体</a></li>
            <li><a href="javascript:;">微软雅黑</a></li>
            <li><a href="javascript:;">新宋体</a></li>
            <li><a href="javascript:;">仿宋</a></li>
        </ul>
    </body>
    </html>
  • 相关阅读:
    你所不知道的mfc…mfc项目索引 &mfc调优指南 &mfc vc添加添加子功能指南
    Cu 大彻大悟内存管理 mm (update 0410)
    [转]Linux iostat监测IO状态
    linux virtual memory layout by moniskiller upload [读书笔记]
    河畔找到的 面经笔经
    【转】Linux本地磁盘(硬盘)介绍
    读写UTF8、Unicode文件
    codesmith执行时提示“调用的目标发生了异常”的处理过程经验。
    DB2表信息以及字段信息的表
    iBatis.NET获取resultMap相关数据
  • 原文地址:https://www.cnblogs.com/mayufo/p/4229155.html
Copyright © 2011-2022 走看看