zoukankan      html  css  js  c++  java
  • jquery实现简单的下拉多选

    html布局:

    <div class="mutiSelect">
        <span>街道列表</span>
        <div class="list">
            <p class="content">请选择</p>
        </div>
        <ul class="listContent">
            <li><input class="all" id="all" type="checkbox">全选</li>
            <li><input class="street" type="checkbox" name="street" value="1"> 街道1</li>
            <li><input class="street" type="checkbox" name="street" value="2"> 街道2</li>
            <li><input class="street" type="checkbox" name="street" value="3"> 街道3</li>
            <li><input class="street" type="checkbox" name="street" value="4"> 街道4</li>
            <li><input class="street" type="checkbox" name="street" value="5"> 街道5</li>
        </ul>
    </div>

    css样式

            *{padding:0;margin:0;}
            ul li,input{list-style: none;}
            .mutiSelect{50%;position: relative;margin:12px 0;text-indent: 3%;}
            .mutiSelect span{20%;height:25px;line-height:25px;display: block;position: absolute;top:0;font-size: 16px;color:#000;}
            .mutiSelect .list{30%;height:25px;line-height:20px;border:1px solid #a3bbc1;position: absolute;top:0;left:20%;}
            .mutiSelect .list p{100%;height:25px;line-height:25px;}
            .listContent{position: absolute;left:20%;30.2%;top:25px;display: none;}
            .listContent li{100%;border:1px solid #a3bbc1;box-sizing: border-box;border-top: none;line-height: 25px;}
    

    jquery

    <script>
        var flag=true;
        var num=0;
        var isc='';
        $(".content").click(function(){
            if(flag){
                flag=false;
                $(".listContent").show();
                isc=''
            }else{
                flag=true;
                $(".listContent").hide();
                for(var i=0;i<$(".street").length;i++){
                    if($(".street").eq(i).is(':checked')){
                        isc +=$(".street").eq(i).val()+",";
                        num++;
                    }
                };
                if(num>0){
                    $(".content").text("街道/镇")
                }else{
                    $(".content").text("请选择")
                }
                console.log(isc);
    
            }
        });
    
    
    //     全选按钮设置
            $("#all").click(function(){
                if( $(this).is(':checked')){
                    $(".street").prop("checked",true);
                }else{
                    $(".street").prop("checked",false);
                }
            });
    
    </script>
    

      

  • 相关阅读:
    排序应用于链表
    线性时间排序算法
    排序算法
    2017计蒜客蓝桥杯模拟赛5
    第六届河南省赛 River Crossing 简单DP
    POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法
    天梯赛 L2-020. 功夫传人 BFS
    天梯赛 L2-019. 悄悄关注 map
    配置在Chrome,Firefox中打开
    http响应状态码大全
  • 原文地址:https://www.cnblogs.com/christineHu/p/6744014.html
Copyright © 2011-2022 走看看