web三级联动选择地址
2018-04-03 22:36
357 查看
地址三级联动,依赖城市city.js文件<script type="text/javascript" src="jquery/jquery-2.2.4.min.js"></script>
<!-- 三级联动城市划分js -->
<script type="text/javascript" src="js/city.js"></script>然后再script中初始化列表<script type="text/javascript">
//三级联动
//设置省份初始化
$(function(){
var html="";
$.each(city.citylist,function(index,item){
html+="<option value='"+item.p+"'>"+item.p+"</option>";
})
$("select[name='province']").html(html);
//
html="";
$.each(city.citylist,function(index,item){
if(item.p=="北京"){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
//省份改变时候,市区做相应的改变
$("select[name='province']").change(function(){
var p=$("select[name='province']").val();
//设置清空乡镇残余文字。
$("select[name='county']").html("");
html="";
$.each(city.citylist,function(index,item){
if(item.p==p){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
});
$("select[name='prefecture']").change(function(){
var p=$("select[name='province']").val();
var c=$("select[name='prefecture']").val();
html="";
$.each(city.citylist,function(index,item){
if(p==item.p){
$.each(item.c,function(index,city){
if(c==city.n){
$.each(city.a,function(index,a){
html+="<option value='"+a.s+"'>"+a.s+"</option>";
})
}
});
}
});
$("select[name='county']").html(html);
})
});
</script>在body中显示标签 <div>
<label>城市:</label>
<div>
<select name="province" id="province"></select>
</div>
</div>
<div>
<div>
<select name="prefecture" id="prefecture"></select>
</div>
</div>
<div>
<div>
<select name="county" id="county"></select>
</div>
</div>整个页面为:<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="<%=basePath%>">
<title>用户注册</title>
<script type="text/javascript" src="jquery/jquery-2.2.4.min.js"></script>
<!-- 三级联动城市划分js -->
<script type="text/javascript" src="js/city.js"></script>
<script type="text/javascript">
//三级联动
//设置省份初始化
$(function(){
var html="";
$.each(city.citylist,function(index,item){
html+="<option value='"+item.p+"'>"+item.p+"</option>";
})
$("select[name='province']").html(html);
//
html="";
$.each(city.citylist,function(index,item){
if(item.p=="北京"){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
//省份改变时候,市区做相应的改变
$("select[name='province']").change(function(){
var p=$("select[name='province']").val();
//设置清空乡镇残余文字。
$("select[name='county']").html("");
html="";
$.each(city.citylist,function(index,item){
if(item.p==p){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
});
$("select[name='prefecture']").change(function(){
var p=$("select[name='province']").val();
var c=$("select[name='prefecture']").val();
html="";
$.each(city.citylist,function(index,item){
if(p==item.p){
$.each(item.c,function(index,city){
if(c==city.n){
$.each(city.a,function(index,a){
html+="<option value='"+a.s+"'>"+a.s+"</option>";
})
}
});
}
});
$("select[name='county']").html(html);
})
});
</script>
</head>
<body>
<div>
<label>城市:</label>
<div>
<select name="province" id="province"></select>
</div>
</div>
<div>
<div>
<select name="prefecture" id="prefecture"></select>
</div>
</div>
<div>
<div>
<select name="county" id="county"></select>
</div>
</div>
</body>
</html>
<!-- 三级联动城市划分js -->
<script type="text/javascript" src="js/city.js"></script>然后再script中初始化列表<script type="text/javascript">
//三级联动
//设置省份初始化
$(function(){
var html="";
$.each(city.citylist,function(index,item){
html+="<option value='"+item.p+"'>"+item.p+"</option>";
})
$("select[name='province']").html(html);
//
html="";
$.each(city.citylist,function(index,item){
if(item.p=="北京"){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
//省份改变时候,市区做相应的改变
$("select[name='province']").change(function(){
var p=$("select[name='province']").val();
//设置清空乡镇残余文字。
$("select[name='county']").html("");
html="";
$.each(city.citylist,function(index,item){
if(item.p==p){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
});
$("select[name='prefecture']").change(function(){
var p=$("select[name='province']").val();
var c=$("select[name='prefecture']").val();
html="";
$.each(city.citylist,function(index,item){
if(p==item.p){
$.each(item.c,function(index,city){
if(c==city.n){
$.each(city.a,function(index,a){
html+="<option value='"+a.s+"'>"+a.s+"</option>";
})
}
});
}
});
$("select[name='county']").html(html);
})
});
</script>在body中显示标签 <div>
<label>城市:</label>
<div>
<select name="province" id="province"></select>
</div>
</div>
<div>
<div>
<select name="prefecture" id="prefecture"></select>
</div>
</div>
<div>
<div>
<select name="county" id="county"></select>
</div>
</div>整个页面为:<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="<%=basePath%>">
<title>用户注册</title>
<script type="text/javascript" src="jquery/jquery-2.2.4.min.js"></script>
<!-- 三级联动城市划分js -->
<script type="text/javascript" src="js/city.js"></script>
<script type="text/javascript">
//三级联动
//设置省份初始化
$(function(){
var html="";
$.each(city.citylist,function(index,item){
html+="<option value='"+item.p+"'>"+item.p+"</option>";
})
$("select[name='province']").html(html);
//
html="";
$.each(city.citylist,function(index,item){
if(item.p=="北京"){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
//省份改变时候,市区做相应的改变
$("select[name='province']").change(function(){
var p=$("select[name='province']").val();
//设置清空乡镇残余文字。
$("select[name='county']").html("");
html="";
$.each(city.citylist,function(index,item){
if(item.p==p){
$.each(item.c,function(index,c){
html+="<option value='"+c.n+"'>"+c.n+"</option>";
})
}
});
$("select[name='prefecture']").html(html);
});
$("select[name='prefecture']").change(function(){
var p=$("select[name='province']").val();
var c=$("select[name='prefecture']").val();
html="";
$.each(city.citylist,function(index,item){
if(p==item.p){
$.each(item.c,function(index,city){
if(c==city.n){
$.each(city.a,function(index,a){
html+="<option value='"+a.s+"'>"+a.s+"</option>";
})
}
});
}
});
$("select[name='county']").html(html);
})
});
</script>
</head>
<body>
<div>
<label>城市:</label>
<div>
<select name="province" id="province"></select>
</div>
</div>
<div>
<div>
<select name="prefecture" id="prefecture"></select>
</div>
</div>
<div>
<div>
<select name="county" id="county"></select>
</div>
</div>
</body>
</html>
相关文章推荐
- ionic开发移动app过程中地址选择部分涉及省市县三级联动
- android 省市县街道地址选择 三级联动 四级联动
- 三级联动的地址选择器
- 微信小程序开发之三级联动地址选择器
- Android 地址选择器,实现省市区三级联动
- js实现选择地址的三级联动(精确到区)
- 地址的三级联动 选择后显示地区并返回服务器Id号(一)
- Android 地址选择器,实现省市区三级联动
- 三级联动地址选择器,遇到的问题记录
- 简单实现仿某宝地址选择三级联动样式
- js三级联动地址选择
- 地址选择 三级联动
- 【2018最新的省市区】获取json,实现三级联动选择省市区(底部源码地址)
- 手把手教你webpack+vue+amaze-vue实现省市区三级联动选择组件
- 地址的三级联动 选择后显示地区并返回服务器Id号(二)
- Axure教程:省市县三级联动选择(全国省市区数据)
- 中国省市区地址三级联动jQuery插件 案例下载
- 三级联动:js实现淘宝地址更改
- Android省市区三级联动滚轮选择(真实项目中提取出来的组件)
- 在ASP.NET MVC中实现一种不同于平常的三级联动、级联方式, 可用于城市、车型选择等多层级联场景