JS开始

二级地域选项的JS部分。
function change() {
var pro = document.getElementById('province'),
scEle = document.getElementsByClassName('scCity'),
gdEle = document.getElementsByClassName('gdCity'),
j,
cnt;
for(var i = 0,len = pro.childNodes.length;i < len; ++i){
if(pro.childNodes[i].nodeType == 1 && pro.childNodes[i].selected){
if(pro.childNodes[i].value == 'sc'){
for(j = 0,cnt = scEle.length;j < cnt; ++j){
setBlock(scEle[j]);
scEle[0].selected = true;
}
for(j = 0,cnt = gdEle.length;j < cnt; ++j){
setNone(gdEle[j]);
}
break;
}
else if(pro.childNodes[i].value == 'gd'){
for(j = 0,cnt = scEle.length;j < cnt; ++j){
setNone(scEle[j]);
}
for(j = 0,cnt = gdEle.length;j < cnt; ++j){
setBlock(gdEle[j]);
gdEle[0].selected = true;
}
break;
}
}
}
function setNone(str){
str.style.display = "none";
}
function setBlock(str){
str.style.display = "block";
}
}

posted @ 2016-04-18 21:04  白小九  阅读(143)  评论(0编辑  收藏  举报