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

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

WBOY
WBOY原創
2016-06-07 11:37:071441瀏覽

全国省市县区街道 无联动下拉选择 数据库及源代码
全国省市县区街道 无联动下拉选择
前端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')->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')->where($where)->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')->where($where)->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')->where($where)->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')->where($where)->select();<br>         $provinces_village = json_encode($provinces);<br>         exit($provinces_village);<br>     }数据库http://blog.jjonline.cn/soft/J_Position/ajing.sql.gz

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn