js省市区级联查询(插件版&无插件版)

实现方式千差万别,满足自己需求的才是最好的。

插件版提供了两种方式:

distpicker版

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href="https://www.jb51.net/css/city.css" type="text/css" /> <script src="https://www.jb51.net/js/jquery-2.2.0.min.js"></script> <script src="https://www.jb51.net/js/distpicker.data.js"></script> <script src="https://www.jb51.net/js/distpicker.js"></script> </head> <body> <h5>Demo:</h5> <form> <div data-toggle="distpicker"> <div> <label for="province1">Province</label> <select></select> </div> <div> <label for="city1">City</label> <select></select> </div> <div> <label for="district1">District</label> <select></select> </div> </div> </form> </body> </html>

js省市区级联查询(插件版&无插件版)


distpicker.data.js 、distpicker.js 下载地址

第二种插件版

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href="https://www.jb51.net/css/city.css" type="text/css" /> <script type="text/javascript" src="https://www.jb51.net/js/jquery.min.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/city.min.js"></script> </head> <body> <div> <div> <form action=""> <div> <lable>所在地区:</lable> <div> <span> <i>请选择省份</i> <ul> <li><a href="javascript:void(0)" alt="请选择省份">请选择省份</a></li> </ul> <input type="hidden" value="请选择省份"> </span> <span> <i>请选择城市</i> <ul> <li><a href="javascript:void(0)" alt="请选择城市">请选择城市</a></li> </ul> <input type="hidden" value="请选择城市"> </span> <span> <i>请选择地区</i> <ul> <li><a href="javascript:void(0)" alt="请选择地区">请选择地区</a></li> </ul> <input type="hidden" value="请选择地区"> </span> </div> </div> </form> </div> <div></div> </div> </body> </html>

js省市区级联查询(插件版&无插件版)

相关js下载地址:链接: jqueryminjs

css下载地址:链接: css

无插件版:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" > </head> <body> <p>&nbsp;</p> <div> <div> <div> <label>所在区域</label> <div> <select> </select> </div> <div> <select> </select> </div> <div> <select> </select> </div> </div> </div> </div> <p>&nbsp;</p> <div>数据来源: <a href="https://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201504/t20150415_712722.html" target="_blank"></a> </div> <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://www.jb51.net/js/pdata.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function() { var html = "<option value=''>== 请选择 ==</option>"; $("#input_city").append(html); $("#input_area").append(html); $.each(pdata, function(idx, item) { if(parseInt(item.level) == 1) { html += "<option value='" + item.name + "' exid='" + item.code + "'>" + item.name + "</option>"; } }); $("#input_province").append(html); $("#input_province").change(function() { if($(this).val() == "") return; $("#input_city option").remove(); $("#input_area option").remove(); var code = $(this).find("option:selected").attr("exid"); code = code.substring(0, 2); var html = "<option value=''>== 请选择 ==</option>"; $("#input_area").append(html); $.each(pdata, function(idx, item) { if(parseInt(item.level) == 2 && code == item.code.substring(0, 2)) { html += "<option value='" + item.name + "' exid='" + item.code + "'>" + item.name + "</option>"; } }); $("#input_city").append(html); }); $("#input_city").change(function() { if($(this).val() == "") return; $("#input_area option").remove(); var code = $(this).find("option:selected").attr("exid"); code = code.substring(0, 4); var html = "<option value=''>== 请选择 ==</option>"; $.each(pdata, function(idx, item) { if(parseInt(item.level) == 3 && code == item.code.substring(0, 4)) { html += "<option value='" + item.name + "' exid='" + item.code + "'>" + item.name + "</option>"; } }); $("#input_area").append(html); }); //绑定 $("#input_province").val("山东省"); $("#input_province").change(); $("#input_city").val("潍坊市"); $("#input_city").change(); $("#input_area").val("诸城市"); }); </script> </body> </html>

js省市区级联查询(插件版&无插件版)


pdata.js下载地址

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwyzp.html