当前位置:网站首页>Classic case of JS operation node (three-level linkage)
Classic case of JS operation node (three-level linkage)
2022-06-22 02:51:00 【Programming Bruce Lee】
introduce
adopt JS operation DOM Element object , Realize three-level linkage , The effect is shown in the figure .
js Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Three level linkage </title>
</head>
<body>
<select name="province" id="province" onchange="changeP(this)">
<option value="-1">-- Please select a province --</option>
</select>
<select name="city" id="city" onclick="changeC(this)">
<option value="">-- Please choose the city --</option>
</select>
<select name="area" id="area">
<option value="">-- Please select zone --</option>
</select>
</body>
<script>
let arrP = [' Hunan province ', ' Hubei province ', ' Guangdong province, '];
let arrC = [
[' Changsha ', ' zhuzhou ', ' Jishou ', ' changde ', ' zhangjiajie '],
[' wuhan ', ' xiangyang ', ' Suizhou ', ' yichang ', ' jingzhou '],
[' Guangzhou ', ' Taishan ', ' foshan ', ' zhongshan ', ' The clouds are floating ']
];
let arrA = [
[
[' Changsha 1', ' Changsha 2', ' Changsha 3', ' Changsha 4', ' Changsha 5'],
[' zhuzhou 1', ' zhuzhou 2', ' zhuzhou 3', ' zhuzhou 4', ' zhuzhou 5'],
[' Jishou 1', ' Jishou 2', ' Jishou 3', ' Jishou 4', ' Jishou 5'],
[' changde 1', ' changde 2', ' changde 3', ' changde 4', ' changde 5'],
[' zhangjiajie 1', ' zhangjiajie ', ' zhangjiajie 3', ' zhangjiajie 4', ' zhangjiajie 5']
],
[
[' wuhan 1', ' wuhan ', ' wuhan 3', ' wuhan 4', ' wuhan 5'],
[' xiangyang 1', ' xiangyang 2', ' xiangyang 3', ' xiangyang 4', ' xiangyang 5'],
[' Suizhou 1', ' Suizhou 2', ' Suizhou 4', ' Suizhou 4', ' Suizhou 5'],
[' yichang 1', ' yichang 2', ' yichang 3', ' yichang 4', ' yichang 5'],
[' jingzhou 1', ' jingzhou 2', ' jingzhou 3', ' jingzhou 4', ' jingzhou 5']
],
[
[' Guangzhou 1', ' Guangzhou 2', ' Guangzhou ', ' Guangzhou 4', ' Guangzhou 5'],
[' Taishan 1', ' Taishan 2', ' Taishan 3', ' Taishan 4', ' Taishan 5'],
[' foshan 1', ' foshan 2', ' foshan 3', ' foshan 4', ' foshan 5'],
[' zhongshan 1', ' zhongshan 2', ' zhongshan 3', ' zhongshan 4', ' zhongshan 5'],
[' The clouds are floating 1', ' The clouds are floating 2', ' The clouds are floating 3', ' The clouds are floating 4', ' The clouds are floating 5']
],
];
// Add province selection
let province = document.getElementById('province');
let area = document.getElementById('area');
let city = document.getElementById('city');
for (let i in arrP) {
let op = document.createElement('option');
op.setAttribute('value', arrP[i]);
op.innerText = arrP[i];
province.appendChild(op);
}
// Save change function
function changeP(provinceH) {
let arr = arrC[provinceH.selectedIndex - 1];
// Let the provinces leave only the first item
if (typeof arr != 'undefined') {
city.options.length = 0;
for (let index in arr) {
// establish Option Object can directly set the text content and value
city.options.add(new Option(arr[index], arr[index]));
}
changeC(city);
} else {
city.innerHTML = "<option value='-1'>-- Please choose the city --</option>";
area.innerHTML = "<option value='-1'>-- Please select zone --</option>";
}
}
// Area change function
function changeC(cityH) {
// Prevent as undefined An error is reported when fetching the array value
if (typeof arrA[province.selectedIndex - 1] != 'undefined') {
let arr = arrA[province.selectedIndex - 1][cityH.selectedIndex];
// Let the provinces leave only the first item
area.options.length = 0;
for (let index in arr) {
// establish Option Object can directly set the text content and value
area.options.add(new Option(arr[index], arr[index]));
}
}
}
</script>
</html>
边栏推荐
- fatal error: png++/png. Hpp: no that file or directory
- Comprehensive interpretation by enterprise reviewers: enterprise growth of [State Grid] China Power Finance Co., Ltd
- 从数据库的分类说起,一文了解图数据库
- [5. high precision subtraction]
- Zap grammar sugar
- 基于xposed框架hook使用
- Vscode custom template, take notes with the template?!
- [8. One dimensional prefix and]
- 图数据库ONgDB Release v-1.0.2
- Latest release: neo4j figure data science GDS 2.0 and aurads GA
猜你喜欢

Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition

Brief analysis of application source code of neo4j intelligent supply chain

背光模组的基本结构与应用

C++ primer Chapter 2 summary of variables and basic types

Latest release: neo4j figure data science GDS 2.0 and aurads GA

Must the database primary key be self incremented? What scenarios do not suggest self augmentation?

【6. 高精度乘法】

Unity3d post process volume profile

Day18qt signal and slot 2021-10-29

Automated tools - monitoring file changes
随机推荐
Sword finger offer 28 Symmetric binary tree
Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization
Game jam development cycle
【Percona-Toolkit】系列之pt-table-checksum和pt-table-sync 数据校验修复神器
With the acceleration of industry wide digital transformation, what kind of storage will be more popular?
Write the processing framework for playing
Neo4j 智能供应链应用源代码简析
Right and left vertical time axis with serial number
Kubernetes code generator use
[Shangshui Shuo series] day two
Parallel search DSU
Huayang smart rushes to Shenzhen Stock Exchange: it plans to raise 400million Fosun Weiying as a shareholder
Try catch of Bash
import和require在浏览器和node环境下的实现差异
Day20qt multiple forms switching idea 2021-10-31
mocklog_ Simulation log
Is the link of Hengtai securities VIP low commission account opening safe?
最热门海量的阿里云盘资源分享
JS special effects in the construction of animated web pages
[4. high precision addition]