JavaScript多级联动的问题
请把下面的代码修改成四级联动、五级联动,谢谢。看回答追加分数!<scriptlanguage="JavaScript"type="text/javascript">//C...
请把下面的代码修改成四级联动、五级联动,谢谢。看回答追加分数!
<script language="JavaScript" type="text/javascript">
//ChangeSelect(上一级的值,下一级Select控件的ID值,下一级Select控件要选中的值(即value而非text),数据源数组名,默认显示字符(如:请选择...如果不写的话会用默认值填充)),第一级的上级值为0
function ChangeSelect(ParentValue, NextId, NextSelectedValue, ArrObj,DefaultStr)
{
StrObj = eval(document.getElementById(NextId));
StrObj.length = 0;
//判断它是二级数据源,还是三级
if (ArrObj.length > 0)
{
if (ArrObj[0].length == 2)
{ArrNum = 0;}
else
{ArrNum = 2;}
}
//显示所有列表
for (i = 0; i < ArrObj.length; i++)
{
if (i == 0)
{
if (DefaultStr == undefined ) DefaultStr="==请选择==";
StrObj.options[StrObj.length] = new Option(DefaultStr, "");
}
if (ArrObj[i][1] == ParentValue)
{
StrObj.options[StrObj.length] = new Option(ArrObj[i][0],ArrObj[i][ArrNum]);
}
}
//选中列表内某一项
for (i = 0; i < StrObj.length; i++)
{
if (StrObj.options[i].value == NextSelectedValue)
{
StrObj.options[i].selected = true;
}
}
//激发下一级的onchange事件以实现多级级联
StrObj.onchange();
}
//省市三维数组数据源
City3 = [
["CategoryName","ParentId","Id"],
["北京","0","010"],
["山西","0","0359"],
["朝阳区","010","001"],
["海淀区","010","002"],
["豆各庄","001","101"],
["十里堡","001","102"],
["中关村","002","201"],
["上地","002","202"],
["运城地区","0359","301"],
["太原市","0359","302"],
["永济市","301","311"],
["小区","302","312"]
];
</script>
<select id="City3001" onchange="ChangeSelect(this.value,'City3002','',City3)" style="width:100px"></select>
<select id="City3002" onchange="ChangeSelect(this.value,'City3003','',City3)" style="width:100px"></select>
<select id="City3003" onchange="" style="width:100px"></select>
<script language="JavaScript" type="text/javascript">ChangeSelect('0','City3001','',City3) </script> 展开
<script language="JavaScript" type="text/javascript">
//ChangeSelect(上一级的值,下一级Select控件的ID值,下一级Select控件要选中的值(即value而非text),数据源数组名,默认显示字符(如:请选择...如果不写的话会用默认值填充)),第一级的上级值为0
function ChangeSelect(ParentValue, NextId, NextSelectedValue, ArrObj,DefaultStr)
{
StrObj = eval(document.getElementById(NextId));
StrObj.length = 0;
//判断它是二级数据源,还是三级
if (ArrObj.length > 0)
{
if (ArrObj[0].length == 2)
{ArrNum = 0;}
else
{ArrNum = 2;}
}
//显示所有列表
for (i = 0; i < ArrObj.length; i++)
{
if (i == 0)
{
if (DefaultStr == undefined ) DefaultStr="==请选择==";
StrObj.options[StrObj.length] = new Option(DefaultStr, "");
}
if (ArrObj[i][1] == ParentValue)
{
StrObj.options[StrObj.length] = new Option(ArrObj[i][0],ArrObj[i][ArrNum]);
}
}
//选中列表内某一项
for (i = 0; i < StrObj.length; i++)
{
if (StrObj.options[i].value == NextSelectedValue)
{
StrObj.options[i].selected = true;
}
}
//激发下一级的onchange事件以实现多级级联
StrObj.onchange();
}
//省市三维数组数据源
City3 = [
["CategoryName","ParentId","Id"],
["北京","0","010"],
["山西","0","0359"],
["朝阳区","010","001"],
["海淀区","010","002"],
["豆各庄","001","101"],
["十里堡","001","102"],
["中关村","002","201"],
["上地","002","202"],
["运城地区","0359","301"],
["太原市","0359","302"],
["永济市","301","311"],
["小区","302","312"]
];
</script>
<select id="City3001" onchange="ChangeSelect(this.value,'City3002','',City3)" style="width:100px"></select>
<select id="City3002" onchange="ChangeSelect(this.value,'City3003','',City3)" style="width:100px"></select>
<select id="City3003" onchange="" style="width:100px"></select>
<script language="JavaScript" type="text/javascript">ChangeSelect('0','City3001','',City3) </script> 展开
2011-07-10
展开全部
这里有一个多级联动下拉select菜单
还可以自己设置默认显示值
里面有代码可以参考
还可以自己设置默认显示值
里面有代码可以参考
参考资料: http://www.blueidea.com/common/shoutbox/redir.asp?9=u&id=11685
展开全部
你这本来就是三级联动,想要四、五级的联动只要继续在后面加1个或2个<select></select>即可:
列如:<script language="JavaScript" type="text/javascript">
//ChangeSelect(上一级的值,下一级Select控件的ID值,下一级Select控件要选中的值(即value而非text),数据源数组名,默认显示字符(如:请选择...如果不写的话会用默认值填充)),第一级的上级值为0
function ChangeSelect(ParentValue, NextId, NextSelectedValue, ArrObj,DefaultStr)
{
StrObj = eval(document.getElementById(NextId));
StrObj.length = 0;
//判断它是二级数据源,还是三级
if (ArrObj.length > 0)
{
if (ArrObj[0].length == 2)
{ArrNum = 0;}
else
{ArrNum = 2;}
}
//显示所有列表
for (i = 0; i < ArrObj.length; i++)
{
if (i == 0)
{
if (DefaultStr == undefined ) DefaultStr="==请选择==";
StrObj.options[StrObj.length] = new Option(DefaultStr, "");
}
if (ArrObj[i][1] == ParentValue)
{
StrObj.options[StrObj.length] = new Option(ArrObj[i][0],ArrObj[i][ArrNum]);
}
}
//选中列表内某一项
for (i = 0; i < StrObj.length; i++)
{
if (StrObj.options[i].value == NextSelectedValue)
{
StrObj.options[i].selected = true;
}
}
//激发下一级的onchange事件以实现多级级联
StrObj.onchange();
}
//省市三维数组数据源
City3 = [
["CategoryName","ParentId","Id"],
["北京","0","010"],
["山西","0","0359"],
["朝阳区","010","001"],
["海淀区","010","002"],
["豆各庄","001","101"],
["十里堡","001","102"],
["中关村","002","201"],
["上地","002","202"],
["运城地区","0359","301"],
["太原市","0359","302"],
["永济市","301","311"],
["永济市2","301","312"],
["小区","302","313"],
["四1","101","011"],
["四2","101","012"]
];
</script>
<select id="City3001" onchange="ChangeSelect(this.value,'City3002','',City3)" style="width:100px"></select>
<select id="City3002" onchange="ChangeSelect(this.value,'City3003','',City3)" style="width:100px"></select>
<select id="City3003" onchange="ChangeSelect(this.value,'City3004','',City3)" style="width:100px"></select>
<select id="City3004" onchange="" style="width:100px"></select>
<script language="JavaScript" type="text/javascript">ChangeSelect('0','City3001','',City3) </script>
你试一下,这个是四联的!
列如:<script language="JavaScript" type="text/javascript">
//ChangeSelect(上一级的值,下一级Select控件的ID值,下一级Select控件要选中的值(即value而非text),数据源数组名,默认显示字符(如:请选择...如果不写的话会用默认值填充)),第一级的上级值为0
function ChangeSelect(ParentValue, NextId, NextSelectedValue, ArrObj,DefaultStr)
{
StrObj = eval(document.getElementById(NextId));
StrObj.length = 0;
//判断它是二级数据源,还是三级
if (ArrObj.length > 0)
{
if (ArrObj[0].length == 2)
{ArrNum = 0;}
else
{ArrNum = 2;}
}
//显示所有列表
for (i = 0; i < ArrObj.length; i++)
{
if (i == 0)
{
if (DefaultStr == undefined ) DefaultStr="==请选择==";
StrObj.options[StrObj.length] = new Option(DefaultStr, "");
}
if (ArrObj[i][1] == ParentValue)
{
StrObj.options[StrObj.length] = new Option(ArrObj[i][0],ArrObj[i][ArrNum]);
}
}
//选中列表内某一项
for (i = 0; i < StrObj.length; i++)
{
if (StrObj.options[i].value == NextSelectedValue)
{
StrObj.options[i].selected = true;
}
}
//激发下一级的onchange事件以实现多级级联
StrObj.onchange();
}
//省市三维数组数据源
City3 = [
["CategoryName","ParentId","Id"],
["北京","0","010"],
["山西","0","0359"],
["朝阳区","010","001"],
["海淀区","010","002"],
["豆各庄","001","101"],
["十里堡","001","102"],
["中关村","002","201"],
["上地","002","202"],
["运城地区","0359","301"],
["太原市","0359","302"],
["永济市","301","311"],
["永济市2","301","312"],
["小区","302","313"],
["四1","101","011"],
["四2","101","012"]
];
</script>
<select id="City3001" onchange="ChangeSelect(this.value,'City3002','',City3)" style="width:100px"></select>
<select id="City3002" onchange="ChangeSelect(this.value,'City3003','',City3)" style="width:100px"></select>
<select id="City3003" onchange="ChangeSelect(this.value,'City3004','',City3)" style="width:100px"></select>
<select id="City3004" onchange="" style="width:100px"></select>
<script language="JavaScript" type="text/javascript">ChangeSelect('0','City3001','',City3) </script>
你试一下,这个是四联的!
更多追问追答
追问
程序我加了个表单,来获取联动的值。
ChangeSelect('0','City3001','0',City3)
追答
你这是一个表单提交到目标‘post.php’;你可以以参数的形式传到php吗!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不懂。。。不过既然回答嘞分数给我呗。。
追问
请不要灌水!
追答
oh,i'm sorry..不过可以和我讲讲是神马么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询