三級聯動使用Jquery和bootstrap進行布局

來源:互聯網
上載者:User

標籤:div   jquer   value   select   red   http   width   change   ctf   

網頁的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

 

三級聯動使用Jquery和bootstrap進行布局

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.