Home php教程 php手册 全国省市县区街道 无联动下拉选择

全国省市县区街道 无联动下拉选择

Jun 07, 2016 am 11:37 AM

全国省市县区街道 无联动下拉选择 数据库及源代码
全国省市县区街道 无联动下拉选择
前端JQ代码
引入jq库<script><br /> $(document).ready(function() {<br /> // 加载所有的省份<br /> $.ajax({<br /> type: "get",<br /> url: "{:U(&#039;Lease/region&#039;)}", // type=1表示查询省份 <br /> dataType: "json",<br /> success: function(data) {<br /> $("#provinces").html("<option value=&#039;&#039;>请选择省份");<br /> $.each(data, function(i, item) {<br /> $("#provinces").append("<option value=&#039;" + item.provice_id + "&#039;>" + item.provice_name + "");<br /> });<br /> }<br /> });<br /> $("#provinces").change(function() {<br /> $.ajax({<br /> type: "get",<br /> url: "{:U(&#039;Lease/regioncity&#039;)}", // type =2表示查询市<br /> data: {<br /> "province_id": $(this).val(),<br /> },<br /> dataType: "json",<br /> success: function(data) {<br /> $("#citys").css(&#039;display&#039;,&#039;block&#039;);<br /> $("#citys").html("<option value=&#039;&#039;>请选择市");<br /> $.each(data, function(i, item) {<br /> $("#citys").append("<option value=&#039;" + item.city_id + "&#039;>" + item.city_name + "");<br /> });<br /> }<br /> });<br /> });<br /> $("#citys").change(function() {<br /> $.ajax({<br /> type: "get",<br /> url: "{:U(&#039;Lease/regioncounty&#039;)}", // type =2表示查询市<br /> data: {<br /> "city_id": $(this).val(),<br /> },<br /> dataType: "json",<br /> success: function(data) {<br /> $("#countys").css(&#039;display&#039;,&#039;block&#039;);<br /> $("#countys").html("<option value=&#039;&#039;>请选择县");<br /> $.each(data, function(i, item) {<br /> $("#countys").append("<option value=&#039;" + item.county_id + "&#039;>" + item.county_name + "");<br /> });<br /> }<br /> });<br /> });<br /> $("#countys").change(function() {<br /> $.ajax({<br /> type: "get",<br /> url: "{:U(&#039;Lease/regiontown&#039;)}", // <br /> data: {<br /> "county_id": $(this).val(),<br /> },<br /> dataType: "json",<br /> success: function(data) {<br /> $("#towns").css(&#039;display&#039;,&#039;block&#039;);<br /> $("#towns").html("<option value=&#039;&#039;>请选择街道");<br /> $.each(data, function(i, item) {<br /> $("#towns").append("<option value=&#039;" + item.town_id + "&#039;>" + item.town_name + "");<br /> });<br /> }<br /> });<br /> });<br /> $("#towns").change(function() {<br /> $.ajax({<br /> type: "get",<br /> url: "{:U(&#039;Lease/regionvillage&#039;)}", // <br /> data: {<br /> "town_id": $(this).val(),<br /> },<br /> dataType: "json",<br /> success: function(data) {<br /> $("#villages").css(&#039;display&#039;,&#039;block&#039;);<br /> $("#villages").html("<option value=&#039;&#039;>请选择社区");<br /> $.each(data, function(i, item) {<br /> $("#villages").append("<option value=&#039;" + item.village_id + "&#039;>" + item.village_name + "");<br /> });<br /> }<br /> });<br /> });<br /> });<br /> </script>html代码<div> <br>                             <select><br>                                 <option>请选择省份</option> <br>                             </select><br>                             <select><br>                                 <option>请选择市</option> <br>                             </select><br>                             <select><br>                                 <option>请选择县</option> <br>                             </select><br>                             <select><br>                                 <option>请选择街道</option> <br>                             </select><br>                             <select><br>                                 <option>请选择社区</option> <br>                             </select><br>                         </div>thinkphp代码//读取省数据库<br>     public function region(){<br>         $provinces=M('Position_provice')-&gt;select();<br>         $provinces_json = json_encode($provinces);<br>         exit($provinces_json);<br>     }<br>     //读取市数据库<br>     public function regioncity(){<br>         $where['province_id']=$_GET['province_id'];<br>         $provinces=M('Position_city')-&gt;where($where)-&gt;select();<br>         $provinces_city = json_encode($provinces);<br>         exit($provinces_city);<br>     }<br>     //读取省/区数据库<br>     public function regioncounty(){<br>         $where['city_id']=$_GET['city_id'];<br>         $provinces=M('Position_county')-&gt;where($where)-&gt;select();<br>         $provinces_county = json_encode($provinces);<br>         exit($provinces_county);<br>     }<br>     //读取街道数据库<br>     public function regiontown(){<br>         $where['county_id']=$_GET['county_id'];<br>         $provinces=M('Position_town')-&gt;where($where)-&gt;select();<br>         $provinces_town = json_encode($provinces);<br>         exit($provinces_town);<br>     }<br>     //读取社区数据库<br>     public function regionvillage(){<br>         $where['town_id']=$_GET['town_id'];<br>         $provinces=M('Position_village')-&gt;where($where)-&gt;select();<br>         $provinces_village = json_encode($provinces);<br>         exit($provinces_village);<br>     }数据库http://blog.jjonline.cn/soft/J_Position/ajing.sql.gz

AD:真正免费,域名+虚机+企业邮箱=0元

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Learn about introductory code examples for Python programming Learn about introductory code examples for Python programming Jan 04, 2024 am 10:50 AM

Learn about introductory code examples for Python programming

PHP variables in action: 10 real-life examples of use PHP variables in action: 10 real-life examples of use Feb 19, 2024 pm 03:00 PM

PHP variables in action: 10 real-life examples of use

How to use PHP to write inventory management function code in the inventory management system How to use PHP to write inventory management function code in the inventory management system Aug 06, 2023 pm 04:49 PM

How to use PHP to write inventory management function code in the inventory management system

From beginner to proficient: Code implementation of commonly used data structures in Go language From beginner to proficient: Code implementation of commonly used data structures in Go language Mar 04, 2024 pm 03:09 PM

From beginner to proficient: Code implementation of commonly used data structures in Go language

Java implements simple bubble sort code Java implements simple bubble sort code Jan 30, 2024 am 09:34 AM

Java implements simple bubble sort code

Go language programming examples: code examples in web development Go language programming examples: code examples in web development Mar 04, 2024 pm 04:54 PM

Go language programming examples: code examples in web development

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces Jul 05, 2023 pm 09:57 PM

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces

Guidance and Examples: Learn to implement the selection sort algorithm in Java Guidance and Examples: Learn to implement the selection sort algorithm in Java Feb 18, 2024 am 10:52 AM

Guidance and Examples: Learn to implement the selection sort algorithm in Java

See all articles