zoukankan      html  css  js  c++  java
  • 选择标签

    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    </head>
    <style>
    *{margin:0;padding:0;}
    ul,li{
    list-style:none;    
    }
    .work,.opc,.age,.stu{
    500px;
    height:30px;    
    }
    .work-item,.opc-item,.age-item,.stu-item{
    50px;
    text-align:center;
    background-color:pink;    
    }
    .all{
    background-color:blue;
    color:#fff;
    }
    </style>
    <body>
    <div class="work">
    <span class="all">300</span>
    <span class="work-item mycode">3001</span>
    <span class="work-item mycode">3002</span>
    <span class="work-item mycode">3003</span>
    </div>
    <div class="opc">
    <span class="all">400</span>
    <span class="opc-item mycode">4001</span>
    <span class="opc-item mycode">4002</span>
    <span class="opc-item mycode">4003</span>
    </div>
    <div class="age">
    <span class="all">500</span>
    <span class="age-item mycode">5001</span>
    <span class="age-item mycode">5002</span>
    <span class="age-item mycode">5003</span>
    </div>
    <div class="stu">
    <span class="all">600</span>
    <span class="stu-item mycode">6001</span>
    <span class="stu-item mycode">6002</span>
    <span class="stu-item mycode">6003</span>
    </div>
    
    <script>
    /*
    var te =[3001,4002,5003];
    var tt = [300];
    for(var j=0;j<te.length;j++){
        var teTs = te[j].toString().substr(0,3);
        if(teTs == tt.toString()){
            te.splice(j,1);
        }
        console.log(teTs);
        console.log(te)
    }
    */
    var test = [300,400,500,600,700];
    var at = 300;
    if(test.indexOf(at)!=-1){
        test.splice(test.indexOf(at),1);
    }
    
    console.log(test);
    console.log(test)
    var allTags=[];
    var tagcodes=[];
    // 查找指定位置
    //Array.prototype.indexOf = function(val) {
    //for (var i = 0; i < this.length; i++) {
    //if (this[i] == val) return i;
    //}
    //return -1;
    //};
    //delete one
    /**
    Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
    this.splice(index, 1);
    }
    };
    **/
    //数组去重
    Array.prototype.unique3 = function(){
    var res = [];
    var json = {};
    for(var i = 0; i < this.length; i++){
    if(!json[this[i]]){
    res.push(this[i]);
    json[this[i]] = 1;
    }
    }
    return res;
    }
    // gel all
    function getAll(){
        $('.all').click(function(){
        allTags.push($(this).html());
        allTags = allTags.unique3();
        console.log(allTags);
        
        //选择全部时去掉标签中子类
        for(var k=0;k<tagcodes.length;k++){
            for(var m=0;m<allTags.length;m++){
                if(tagcodes[k].toString().substr(0,3)==allTags[m].toString()){
                    tagcodes.splice(k,1);
                }
            }
        }
        console.log(tagcodes)
            
        console.log('这里是标签')
        console.log(tagcodes);
        console.log('这里是全部')
        console.log(allTags)
        
        })    
    }
    //选择标签 单选    
    function getTags(){
    
        $('.mycode').click(function(){
        //console.dir($(this).html());
        //保证是单选
        for(var l=0;l<tagcodes.length;l++){
            if(tagcodes[l].toString().substr(0,3)==$(this).html().toString()){
                tagcodes.splice(l,1)
            }
        }
        tagcodes.push($(this).html());
        tagcodes=tagcodes.unique3();
        //选择标签时去掉相应的全部
            for(var j=0;j<tagcodes.length;j++){
                for(var n=0;n<allTags.length;n++){
                    if(tagcodes[j].toString().substr(0,3)==allTags[n].toString()){
                        console.log(allTags[n])
                        allTags.splice(n,1)
                    }
                }
            }
            console.log(allTags)
            console.log(tagcodes)
        });
    }
    
    
    $(function(){
    getAll();    
    getTags();
    var t = 1324;
    var bn = 12235;
    //console.log(bn.indexOf(1))
    })
    </script>
    </body>
    </html>
  • 相关阅读:
    linux安装 Android Studio详细教程,支持性较差,需要安装最新底层库内核的linux
    QT、QTE、qtopia区别
    Sublime Text 有哪些使用技巧
    华为5700交换机通过外部开源protal和本地aaa用户认证的一些问题
    离奇“undefined reference”错误分析与解决方案
    GNU工具链学习笔记
    gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
    揭开Linux操作系统的Swap交换区之谜
    invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
    学习JavaScript
  • 原文地址:https://www.cnblogs.com/vali/p/6539464.html
Copyright © 2011-2022 走看看