<html>
<head>
<meta charset="utf-8">
<title>二维数组</title>
</head>
<body>
<select id="one"></select>
<select id="two"></select>
<script type="text/javascript">
var one=document.getElementById("one");
var two=document.getElementById("two");
var one1=["数字","英语","汉字"];
var two1=[["1","2","3","4"],["one","two","three","four"],["一","二","三","四"]];
var str1="";
for(var n=0;n<one1.length;n++){
str1=str1+"<option>"+one1[n]+"</option>";
}
one.innerHTML=str1;
var str2="";
for(var n=0;n<two1.length;n++){
str2=str2+"<option>"+two1[0][n]+"</option>"
}
two.innerHTML=str2;
one.οnchange=function(){
var str3="";
for(var n=0;n<two1[one.selectedIndex].length;n++){
str3=str3+"<option>"+two1[one.selectedIndex][n]+"</option>"
}
two.innerHTML=str3;
}
</script>
</body>
</html>
JavaScript——二维数组实现下拉列表
最新推荐文章于 2023-03-13 18:01:13 发布