网页部分:
<div class="area" style="width:100%;height:100%;">
<select class="area1" name="area" id="sheng" >
<option name="xxx" value="0">请选择省</option>
</select>
<select class="area1" name="area" id="shi">
<option value="1">请选择市</option>
</select>
<select class="area1" name="area" id="xian">
<option value="2">请选择县</option>
</select>
</div>
js部分:
function area(){
// alert("x")
$.ajax({
url:"/ssx/",
type:"GET",
dataType:"JSON",
data:{
'sheng':"1"
},
success:function (data) {
$.each(data,function (i,j) {
if (i%10000==0){
$('.area').children().eq(0).append('<option class="hidden1" name="xxx" value='+i+'>'+ j[1] +'</option>')
}else {
}
})
alert("read")
$('.area').children().eq(0).change(function () {
$('.hidden2').remove()
$('.hidden3').remove()
var sheng = $('.area').children().eq(0).val()
alert(sheng)
if (sheng>3){
$.each(data,function (i,j) {
if (j[2]==sheng){
$('.area').children().eq(1).append('<option class="hidden2" name="xxx" value='+i+'>'+ j[1] +'</option>')
}
})
}
})
$('.area').children().eq(1).change(function () {
$('.hidden3').remove()
var shi = $('.area').children().eq(1).val()
alert(sheng)
if (shi>3){
$.each(data,function (i,j) {
if (j[2]==shi){
$('.area').children().eq(2).append('<option class="hidden3" name="xxx" value='+i+'>'+ j[1] +'</option>')
}
})
}
})
}
})
}
views:
def ssx(request):
sheng = request.GET['sheng']
print(sheng)
area = Ssx.objects.all()
content = dict()
for a in area:
content[a.id] = [a.id, a.area, a.temp]
return JsonResponse(content)
效果图:
省市县选择效果图.jpg 地区数据库表部分.jpg
网友评论