3个回答
2013-09-18
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<head>
<title> 代码实例:级联菜单 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,CNLei.y.l@gmail.com">
</head>
<body>
<select id="BigCate" name="BigCate" size="1" onchange="Redirect(this.options.selectedIndex)">
<option value="">全市</option>
<option value="">主城区</option>
<option value="">分公司</option></select>
<select id="SmlCate" name="SmlCate" size="1">
<option value="1">全市</option>
</select>
<script type="text/javascript">
<!--
var groups = document.getElementById("BigCate").options.length;
var group = new Array(groups)
for (i = 0; i < groups; i ++)
group[i] = new Array()group[0][0] = new Option("全市","ALL")group[1][0] = new Option("北部新区局","CJ0")
group[1][1] = new Option("杨家坪局","CY0")
group[1][2] = new Option("沙坪坝局","CP0")
group[1][3] = new Option("观音桥局","CG0")
group[1][4] = new Option("上清寺局","CS0")
group[1][5] = new Option("南坪局","CN0")group[2][0] = new Option("渝北电信公司","CF0")
group[2][1] = new Option("璧山电信公司","CA0")
group[2][2] = new Option("江津电信公司","CU0")
group[2][3] = new Option("合川电信公司","CK0")
group[2][4] = new Option("北碚电信公司","CI0")group[2][5] = new Option("巴南电信公司","CB0")
group[2][6] = new Option("永川电信公司","CH0")
group[2][7] = new Option("万州电信公司","WW0")
var temp = document.getElementById("SmlCate");
function Redirect(x){ for (m = temp.options.length-1; m > 0; m --)
temp.options[m] = null
for (i = 0; i < group[x].length; i ++){
temp.options[i] = new Option(group[x][i].text,group[x][i].value);
alert(group[x][i].value);
}
temp.options[0].selected = true
}
//-->
</script></body>
</html> 这个代码是入门的最佳辅助代码
<html xmlns=" http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<head>
<title> 代码实例:级联菜单 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,CNLei.y.l@gmail.com">
</head>
<body>
<select id="BigCate" name="BigCate" size="1" onchange="Redirect(this.options.selectedIndex)">
<option value="">全市</option>
<option value="">主城区</option>
<option value="">分公司</option></select>
<select id="SmlCate" name="SmlCate" size="1">
<option value="1">全市</option>
</select>
<script type="text/javascript">
<!--
var groups = document.getElementById("BigCate").options.length;
var group = new Array(groups)
for (i = 0; i < groups; i ++)
group[i] = new Array()group[0][0] = new Option("全市","ALL")group[1][0] = new Option("北部新区局","CJ0")
group[1][1] = new Option("杨家坪局","CY0")
group[1][2] = new Option("沙坪坝局","CP0")
group[1][3] = new Option("观音桥局","CG0")
group[1][4] = new Option("上清寺局","CS0")
group[1][5] = new Option("南坪局","CN0")group[2][0] = new Option("渝北电信公司","CF0")
group[2][1] = new Option("璧山电信公司","CA0")
group[2][2] = new Option("江津电信公司","CU0")
group[2][3] = new Option("合川电信公司","CK0")
group[2][4] = new Option("北碚电信公司","CI0")group[2][5] = new Option("巴南电信公司","CB0")
group[2][6] = new Option("永川电信公司","CH0")
group[2][7] = new Option("万州电信公司","WW0")
var temp = document.getElementById("SmlCate");
function Redirect(x){ for (m = temp.options.length-1; m > 0; m --)
temp.options[m] = null
for (i = 0; i < group[x].length; i ++){
temp.options[i] = new Option(group[x][i].text,group[x][i].value);
alert(group[x][i].value);
}
temp.options[0].selected = true
}
//-->
</script></body>
</html> 这个代码是入门的最佳辅助代码
2013-09-18
展开全部
function sel(){ var s1=document.getElementById("sel1");var s2=document.getElementById("sel2"); for(var i=0;i<3;i++){ var option=new Option(s1.value+i+1); s2.options[i]=option;}} <select id="sel1" onchange="sel()"> <option value=1>1</option><option value=2>2</option> </select><select id="sel2" > </select> 我写了个大体的意思,没有验证级联的关健就是在函数里的赋值。动态添加过程。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1、网上找现成的插件
2、简单的二级联动,通过select框的onchange事件去动态写入第二个select框的option属性
2、简单的二级联动,通过select框的onchange事件去动态写入第二个select框的option属性
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询