zoukankan      html  css  js  c++  java
  • html+jq实现全国省的单选,弹框输入input

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>省单选组件jq</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    </head>
    <body>
        <div class="area">
            <input class="form-control" type="text" id="province" name="province" value="" onfocus="setStyle()" placeholder="请输入省份(不填默认全国投放)">
            <div id="content">
                <div id="areaList">
    
                </div>
                <button class="reset">取消</button>
                <button onClick='get()'>确认</button>
            </div>
        </div>
    </body>
    <script src="./address.js"></script>
    <script>
        function getData(){
            let areasList = []
            for(item in areas){
                let citys = []
                let objs = {
                    province:item,
                    citys:item.indexOf("") != -1?'':citys,
                    show:false,
                    IsCheckeds:false
                }
                for(i in areas[item]){
                    let obj = {
                        city:areas[item][i],
                        IsChecked:false
                    }
                    citys.push(obj)
                }
                areasList.push(objs)
            }
            console.log(areasList)
            view(areasList)
        }
        function view(areasList){
            $(areasList).each(function(i){
                var str="<label class='radio'><input type='radio' value='"+this.province+"' name='area'>"+this.province+"<span>("+this.citys.length+")</span></label>";
                var a=$(str);
                a.appendTo($("#areaList"))
            })
        }
        function setStyle(){
            $('#content').toggleClass('display')
        }
        function get(){
            let arr = []
            $('input[name="area"]').each(function(){
                if($(this).prop('checked'))  $('#province').val($(this).val())
            })
        }
        getData()
    </script>
    <script>
        $(function(){
            $('#content').click(function(){
                $(this).toggleClass('display')
            })
            $('.reset').click(function(){
                $('#content').removeClass('display')
                event.stopPropagation();         //阻止按钮穿透
            })
        })
    </script>
    <style>
    .area #content{
        position: absolute;
        left: 8px;
        top: 44px;
        width: 600px;
        border: 1px solid #ccc3c3;
        border-radius: 3px;
        padding: 10px 0;
        display: none;
        background: white;
    }
    #content button{
        float: right;
    }
    #province{
        width: 400px;
        line-height: 28px;
        text-indent: 10px;
    }
    .display{
        display: block!important;
    }
    .radio{
        font-size: 14px;
        margin:10px 15px;
        display: inline-block;
    }
    </style>

    效果一般,帮后台写的,vue框架与tp5框架不知道 咋兼容,

    下一篇:纯vue.js实现省市选择

  • 相关阅读:
    C语言:运算结果保留两位小数
    FFmpeg: AVFrame中的data和extend_data的区别
    android studio: 配置版权信息(转)
    C++: C++11 成员函数作为pthread线程 (转)
    android studio: 取消行注释在第一列
    C 语言 int 读写是否需要加锁
    【转】浅析Linux中的零拷贝技术--简单形象
    【转】Linux 内核态与用户态--简明清晰的介绍
    delete如何找到多重继承对象的内存块起始地址
    【转】内存管理内幕mallco及free函数实现--简易内存分配器、内存池、GC技术
  • 原文地址:https://www.cnblogs.com/wd163/p/13524446.html
Copyright © 2011-2022 走看看