简述一下JS中二维数组的作用和用法,举一个例子来说明
展开全部
引用回答的别人的问题,里面正是二维数组的用法,和具体的例子。
<html>
<head>
</head>
<body>
<form name="frm">
<select name="s1" onChange="redirec(document.frm.s1.options.selectedIndex)">
<option value="0" selected>请选择</option>
<option value="1">广东</option>
<option value="2">广西</option>
<option value="3">湖南</option>
<option value="4">河北</option>
</select>
<select name="s2">
<option value="0" selected>请选择</option>
</select>
</form>
<script language="javascript">
var select1_len = document.frm.s1.options.length;
var select2 = new Array(select1_len);
for (i=0; i<select1_len; i++)
{
select2[i] = new Array();
}
select2[0][0] = new Option("请选择", " ");
select2[1][0] = new Option("广州", "10" );
select2[1][1] = new Option("深圳", "11" );
select2[1][2] = new Option("asd", "12" );
select2[2][0] = new Option("桂林", "20" );
select2[2][1] = new Option("南宁", "21" );
select2[3][0] = new Option("长沙", "30" );
select2[4][0] = new Option("11", "40" );
function redirec(x)
{
var temp = document.frm.s2;
for (i=0;i<select2[x].length;i++)
{
temp.options[i]=new Option(select2[x][i].text,select2[x][i].value);
}
var len = select2[x].length;
while( len < temp.options.length){
temp.options.remove(len);
}
temp.options[0].selected=true;
}
</script>
</body>
</html>
<html>
<head>
</head>
<body>
<form name="frm">
<select name="s1" onChange="redirec(document.frm.s1.options.selectedIndex)">
<option value="0" selected>请选择</option>
<option value="1">广东</option>
<option value="2">广西</option>
<option value="3">湖南</option>
<option value="4">河北</option>
</select>
<select name="s2">
<option value="0" selected>请选择</option>
</select>
</form>
<script language="javascript">
var select1_len = document.frm.s1.options.length;
var select2 = new Array(select1_len);
for (i=0; i<select1_len; i++)
{
select2[i] = new Array();
}
select2[0][0] = new Option("请选择", " ");
select2[1][0] = new Option("广州", "10" );
select2[1][1] = new Option("深圳", "11" );
select2[1][2] = new Option("asd", "12" );
select2[2][0] = new Option("桂林", "20" );
select2[2][1] = new Option("南宁", "21" );
select2[3][0] = new Option("长沙", "30" );
select2[4][0] = new Option("11", "40" );
function redirec(x)
{
var temp = document.frm.s2;
for (i=0;i<select2[x].length;i++)
{
temp.options[i]=new Option(select2[x][i].text,select2[x][i].value);
}
var len = select2[x].length;
while( len < temp.options.length){
temp.options.remove(len);
}
temp.options[0].selected=true;
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询