Home > Web Front-end > JS Tutorial > jquery realizes the replacement of province and city select drop-down box (sample code)_jquery

jquery realizes the replacement of province and city select drop-down box (sample code)_jquery

WBOY
Release: 2016-05-16 16:58:47
Original
991 people have browsed it

Province and city corresponding implementation:

More selective provinces to determine city content

jsp code:

Copy code The code is as follows:


Province
County , city


js code:
Copy code The code is as follows:

function appendShi(shi) {//String splicing, splicing urban area
var fjs='';
for(var i=0;i {
fjs = '';
}
return fjs;
}
$(function() {
var prince = ['Fujian','Beijing','Shandong','Shanghai'];
var fjs = ['Xiamen','Quanzhou','Fuzhou'];
var bjs = ['Beijing',' Chaoyang District','Haidian District','Pinggu District'];
var shs = ['Huangpu District','Changning District','Baoshan District','Jiading District'];
var sds = [ 'Jinan','Qingdao','Yantai','Rizhao','Laiwu','sss'];

$("select[name='prin']").change(function() {
var shi = $("#sel2");//Get the second select
var prin = $("select[name='prin'][select option:selected]");// Get the value of the selected identity
var newShiSel = $('');//
if (prin.val() == 'Fujian'){
newShiSel.append(appendShi(fjs));
}
if (prin.val() == 'Beijing') {
newShiSel.append(appendShi(bjs));
}
if (prin.val() == 'Shanghai') {
newShiSel.append(appendShi(shs));
}
if (prin.val() == 'Shandong') {
newShiSel.append(appendShi(sds));
}
shi.replaceWith(newShiSel);
} );
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template