代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
省:
<select style="width: 100px;" id="pre" onchange="chg(this);">
<option value="-1">请选择</option>
</select>
市:
<select style="width: 100px;" id="city" onchange="chg2(this)" ;>
</select>
区:
<select style="width: 100px;" id="area" onchange="chg3(this)">
</select>
<div>
<input type="hidden" id="a">
<input type="hidden" id="b">
<input type="hidden" id="c">
</div>
</body>
<script>
//声明省
var pres = ["小学", "初中", "高中"]; //直接声明Array
//声明市
var cities = [
["一年级", "二年级", "三年级", "四年级", "五年级", "六年级"],
["初一", "初二", "初三"],
["高一", "高二", "高三"]
];
var areas = [
[
["语文", "数学", "英语"],
["语文", "数学", "英语"],
["语文", "数学", "英语"],
["语文", "数学", "英语"],
["语文", "数学", "英语"],
["语文", "数学", "英语"]
],
[
["语文", "数学", "英语","物理","化学"],
["语文", "数学", "英语","物理","化学"],
["语文", "数学", "英语","物理","化学"]
],
[
["语文", "数学", "英语","物理","化学"],
["语文", "数学", "英语","物理","化学"],
["语文", "数学", "英语","物理","化学"]
]
]
//设置一个省的公共下标
var pIndex = -1;
var preEle = document.getElementById("pre");
var cityEle = document.getElementById("city");
var areaEle = document.getElementById("area");
//先设置省的值
for (var i = 0; i < pres.length; i++) {
//声明option.<option value="pres[i]">Pres[i]</option>
var op = new Option(pres[i], i);
//添加
preEle.options.add(op);
}
function chg(obj) {
if (obj.value == -1) {
cityEle.options.length = 0;
areaEle.options.length = 0;
}
//获取值
var val = obj.value;
pIndex = obj.value;
//获取ctiry
var cs = cities[val];
//获取默认区
var as = areas[val][0];
//先清空市
cityEle.options.length = 0;
areaEle.options.length = 0;
for (var i = 0; i < cs.length; i++) {
var op = new Option(cs[i], i);
cityEle.options.add(op);
}
for (var i = 0; i < as.length; i++) {
var op = new Option(as[i], i);
areaEle.options.add(op);
}
document.getElementById('a').value=parseInt(val)+1;
document.getElementById('b').value=parseInt(document.getElementById('city').value)+1;
document.getElementById('c').value=parseInt(document.getElementById('area').value)+1;
}
function chg2(obj) {
var val = obj.selectedIndex;
var as = areas[pIndex][val];
areaEle.options.length = 0;
for (var i = 0; i < as.length; i++) {
var op = new Option(as[i], i);
areaEle.options.add(op);
}
document.getElementById('b').value=parseInt(val)+1;
document.getElementById('c').value=parseInt(document.getElementById('area').value)+1;
}
function chg3(obj) {
var val = obj.selectedIndex;
document.getElementById('c').value=parseInt(val)+1;
}
</script>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。