• 省市区地址三级联动jQuery插件Distpicker使用


    插件下载地址

    http://www.jq22.com/jquery-info8054

    效果如下:


    使用:

    1.引入js

    <script src="http://www.jq22.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="js/distpicker.data.js"></script>
    <script src="js/distpicker.js"></script>
    <script src="js/main.js"></script>

    2.根据demo示例,写div

    <div data-toggle="distpicker">
        <select id="eprovinceName" data-province="浙江省" name="provinceName"></select>
        <select id="ecityName" data-city="杭州市" name="cityName"></select>
        <select id="edistrictName" data-district="西湖区" name="districtName"></select>
    </div>

    3.用户选择值value的获取

    <script>
    $("#tijiao").click(function(){
    var province = $("#eprovinceName").find("option:selected").text();  
    var city = $("#ecityName").find("option:selected").text();  
    var district = $("#edistrictName").find("option:selected").text();  
    console.log(province);
    console.log(city);
    console.log(district);
    });
    </script>

    完整代码如下:

    <!DOCTYPE html>
    <html lang="zh">
    
    <body>
    <div data-toggle="distpicker">
        <select id="eprovinceName" data-province="浙江省" name="provinceName"></select>
        <select id="ecityName" data-city="杭州市" name="cityName"></select>
        <select id="edistrictName" data-district="西湖区" name="districtName"></select>
    </div>	
    	<input type='button'  value="提交"  id='tijiao'>
    </body>	
    
    <script src="http://www.jq22.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="js/distpicker.data.js"></script>
    <script src="js/distpicker.js"></script>
    <script src="js/main.js"></script>
    <script>
    	$("#tijiao").click(function(){
    		var province = $("#eprovinceName").find("option:selected").text();  
    		var city = $("#ecityName").find("option:selected").text();  
    		var district = $("#edistrictName").find("option:selected").text();  
    		console.log(province);
    		console.log(city);
    		console.log(district);
    	});	
    </script> 
    </html>

    特别注意:提交表单是,不需要上面那么麻烦

    直接在select上加name属性即可

    <select data-province="北京市" class="select" name="province"></select>
    <select data-city="北京市市辖区" class="select" name="city"></select>
    <select data-district="顺义区" class="select" name="district"></select>



  • 相关阅读:
    小希的迷宫(hdu1272 并查集)
    How many Fibs?(poj 2413)大数斐波那契
    图练习-BFS-从起点到目标点的最短步数(sdut 2830)邻接边表
    最大流(EK)
    趣写算法系列之--匈牙利算法(真的很好理解)
    Saving Princess claire_(hdu 4308 bfs模板题)
    Knight Moves(hdu1372 bfs模板题)
    The Die Is Cast(poj 1481简单的双dfs)
    Oil Deposits(poj 1526 DFS入门题)
    WTL:下载、安装、初见
  • 原文地址:https://www.cnblogs.com/idjl/p/9610604.html
Copyright © 2020-2023  润新知