全国省市县区街道 无联动下拉选择
Jun 07, 2016 am 11:37 AM全国省市县区街道 无联动下拉选择 数据库及源代码
前端JQ代码
引入jq库<script><br />
$(document).ready(function() {<br />
// 加载所有的省份<br />
$.ajax({<br />
type: "get",<br />
url: "{:U('Lease/region')}", // type=1表示查询省份 <br />
dataType: "json",<br />
success: function(data) {<br />
$("#provinces").html("<option value=''>请选择省份");<br />
$.each(data, function(i, item) {<br />
$("#provinces").append("<option value='" + item.provice_id + "'>" + item.provice_name + "");<br />
});<br />
}<br />
});<br />
$("#provinces").change(function() {<br />
$.ajax({<br />
type: "get",<br />
url: "{:U('Lease/regioncity')}", // type =2表示查询市<br />
data: {<br />
"province_id": $(this).val(),<br />
},<br />
dataType: "json",<br />
success: function(data) {<br />
$("#citys").css('display','block');<br />
$("#citys").html("<option value=''>请选择市");<br />
$.each(data, function(i, item) {<br />
$("#citys").append("<option value='" + item.city_id + "'>" + item.city_name + "");<br />
});<br />
}<br />
});<br />
});<br />
$("#citys").change(function() {<br />
$.ajax({<br />
type: "get",<br />
url: "{:U('Lease/regioncounty')}", // type =2表示查询市<br />
data: {<br />
"city_id": $(this).val(),<br />
},<br />
dataType: "json",<br />
success: function(data) {<br />
$("#countys").css('display','block');<br />
$("#countys").html("<option value=''>请选择县");<br />
$.each(data, function(i, item) {<br />
$("#countys").append("<option value='" + item.county_id + "'>" + item.county_name + "");<br />
});<br />
}<br />
});<br />
});<br />
$("#countys").change(function() {<br />
$.ajax({<br />
type: "get",<br />
url: "{:U('Lease/regiontown')}", // <br />
data: {<br />
"county_id": $(this).val(),<br />
},<br />
dataType: "json",<br />
success: function(data) {<br />
$("#towns").css('display','block');<br />
$("#towns").html("<option value=''>请选择街道");<br />
$.each(data, function(i, item) {<br />
$("#towns").append("<option value='" + item.town_id + "'>" + item.town_name + "");<br />
});<br />
}<br />
});<br />
});<br />
$("#towns").change(function() {<br />
$.ajax({<br />
type: "get",<br />
url: "{:U('Lease/regionvillage')}", // <br />
data: {<br />
"town_id": $(this).val(),<br />
},<br />
dataType: "json",<br />
success: function(data) {<br />
$("#villages").css('display','block');<br />
$("#villages").html("<option value=''>请选择社区");<br />
$.each(data, function(i, item) {<br />
$("#villages").append("<option value='" + item.village_id + "'>" + 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元

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Learn about introductory code examples for Python programming

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

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

Java implements simple bubble sort code

Go language programming examples: code examples in web development

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
