博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三级联动使用Jquery和bootstrap进行布局
阅读量:6569 次
发布时间:2019-06-24

本文共 3999 字,大约阅读时间需要 13 分钟。

网页的html代码

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />
<title></title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/20170720.css" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/from3.js"></script>

</head>

<body>

<div class="container">
<div class="container-fluid">
<div class="row">
<div class="col-lg-7 colRowForm">
<div class="colRowFormBlue">
<label >省份:</label>
<select id="province">
<option>请选择</option>
<!--<option>河南</option>
<option>山东</option>-->
</select>
<label>城市:</label>
<select id="provinceCity" class="slectFrom">
<!--<option>请选择</option>-->
</select>
<label>街道:</label>
<select id="Citystreet" class="slectFrom">
</select>
</div>
</div>
<div class="col-lg-5 colRowForm">
<div class="colRowFormBlue">
</div>
</div>
</div>

</div>

</div>

</body>

</html>

20170720.css对应的样式

.colRowForm{

border: 1px solid red;
height: 500px;
}
.colRowFormBlue{
border: 2px solid blue;
height: 200px;
max-width:100% ;
}
.slectFrom{
width: 60px;
}

from3.js对应的js文件内容

$(function() {

json = [{
"code": "01",
"name": "河南",
"city": [{
"codec": "0101",
"namec": "郑州",
"streetc": [{
"codeCc": "010101",
"nameCc": "金水区"
}, {
"codeCc": "010102",
"nameCc": "惠济区"
}, {
"codeCc": "010103",
"nameCc": "二七区"
}]
}, {
"codec": "0102",
"namec": "商丘",
"streetc": [{
"codeCc": "010201",
"nameCc": "商丘街区1"
}, {
"codeCc": "010202",
"nameCc": "商丘街区2"
}, {
"codeCc": "010203",
"nameCc": "商丘街区3"
}]
}, {
"codec": "0103",
"namec": "信阳",
"streetc": [{
"codeCc": "010201",
"nameCc": "信阳街区1"
}, {
"codeCc": "010201",
"nameCc": "信阳街区2"
}, {
"codeCc": "010201",
"nameCc": "信阳街区3"
}]
}]
},
{
"code": "02",
"name": "山东",
"city": [{
"codec": "0201",
"namec": "淄博",
"streetc": [{
"codeCc": "010201",
"nameCc": "淄博街区1"
}, {
"codeCc": "010201",
"nameCc": "淄博街区2"
}, {
"codeCc": "010201",
"nameCc": "淄博街区3"
}]
}, {
"codec": "0202",
"namec": "青岛",
"streetc": [{
"codeCc": "010201",
"nameCc": "青岛街区1"
}, {
"codeCc": "010201",
"nameCc": "青岛街区2"
}, {
"codeCc": "010201",
"nameCc": "青岛街区3"
}]
}, {
"codec": "0203",
"namec": "潍坊",
"streetc": [{
"codeCc": "010201",
"nameCc": "潍坊街区1"
}, {
"codeCc": "010201",
"nameCc": "潍坊街区2"
}, {
"codeCc": "010201",
"nameCc": "潍坊街区3"
}]
}]
},
{
"code": "03",
"name": "江苏",
"city": [{
"codec": "0301",
"namec": "苏州",
"streetc": [{
"codeCc": "010201",
"nameCc": "苏州街区1"
}, {
"codeCc": "010201",
"nameCc": "苏州街区2"
}, {
"codeCc": "010201",
"nameCc": "苏州街区3"
}]
}, {
"codec": "0302",
"namec": "南京",
"streetc": [{
"codeCc": "010201",
"nameCc": "南京街区1"
}, {
"codeCc": "010201",
"nameCc": "南京街区2"
}, {
"codeCc": "010201",
"nameCc": "南京街区3"
}]
}, {
"codec": "0303",
"namec": "无锡",
"streetc": [{
"codeCc": "010201",
"nameCc": "无锡街区1"
}, {
"codeCc": "010201",
"nameCc": "无锡街区2"
}, {
"codeCc": "010201",
"nameCc": "无锡街区3"
}]
}]
}

];

$.each(json, function(index, row) {
$("#province").append("<option value=" + row.code + ">" + row.name + "</option>");

});

$("#province").change(function() {
var province = $(this).val();
if(province == "请选择") {
return;
} else {
provinceCity(province);
}
});
$("#provinceCity").change(function(){
var cityName=$(this).val();
cityStreet(cityName);
});

});

function provinceCity(nameProvince) {

$("#provinceCity").empty();
$("#Citystreet").empty();
$.each(json, function(index, row) {
if(row.code == nameProvince) {
$.each(row.city, function(indec, rowc) {
$("#provinceCity").append("<option value=" + rowc.codec + ">" + rowc.namec + "</option>");
if(indec == 0) {
$.each(rowc.streetc, function(indeCc, rowCc) {
$("#Citystreet").append("<option value=" + rowCc.codeCc + ">" + rowCc.nameCc + "</option>");
});
}
});
}
});
};

function cityStreet(nameCity) {

$("#Citystreet").empty();
$.each(json,function(index,row){
$.each(row.city,function(indec,rowc){
if(rowc.codec == nameCity)
{
$.each(rowc.streetc,function(indeCc,rowCc) {
$("#Citystreet").append("<option value=" + rowCc.codeCc + ">" + rowCc.nameCc + "</option>");
});
}
});
});

};

相关文件的

http://pan.baidu.com/s/1geLTzSR

 

转载于:https://www.cnblogs.com/assiduosd/p/7213715.html

你可能感兴趣的文章
window.location.replace vs window.location.href
查看>>
CVPR 2018:阿里提出应用 LocalizedGAN 进行半监督训练
查看>>
被劫持的wordpress.com账户被用来感染站点
查看>>
分享一下最近看的东西
查看>>
《大数据、小数据、无数据:网络世界的数据学术》一 第2章 何为数据 2.1 引言...
查看>>
寓教于乐的顶峰:新一届大学生集群竞赛火热开战
查看>>
《计算机科学与工程导论:基于IoT和机器人的可视化编程实践方法第2版》一第1章 职业发展机会和团队建设...
查看>>
HBase BlockCache系列 - 探求BlockCache实现机制
查看>>
【参与有奖】您用的MySQL、MongoDB、Redis等服务被勒索过吗?
查看>>
Java核心技术卷I基础知识1.2.6 体系结构中立
查看>>
Libvirt 虚拟化库介绍
查看>>
《Spring 5 官方文档》26. JMS(一)
查看>>
《Python Cookbook(第2版)中文版》——1.11 检查一个字符串是文本还是二进制
查看>>
Tkinter之Label
查看>>
PostgreSQL merge json的正确姿势
查看>>
java反射
查看>>
【IOS-COCOS2D游戏开发之二】COCOS2D 游戏开发资源贴(教程以及源码)
查看>>
nodejs安装记录
查看>>
Android2.2 API 中文文档系列(9) —— ZoomButton
查看>>
pcDuino 刷系统-卡刷
查看>>