javascript实现多级联动下拉菜单的方法
更新时间:2015年02月06日 11:18:04 作者:飞雪
这篇文章主要介绍了javascript实现多级联动下拉菜单的方法,通过javascript自定义函数实现对多级联动下拉菜单的操作,是非常实用的技巧,需要的朋友可以参考下
本文实例讲述了javascript实现多级联动下拉菜单的方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[3] = "列二";
arrItemsGrp1[3] = 1;
arrItems1[4] = "列二三";
arrItemsGrp1[4] = 1;
arrItems1[5] = "列二四";
arrItemsGrp1[5] = 1;
arrItems1[6] = "列三";
arrItemsGrp1[6] = 2;
arrItems1[7] = "列三一";
arrItemsGrp1[7] = 2;
arrItems1[0] = "列四";
arrItemsGrp1[0] = 3;
arrItems1[1] = "列四一";
arrItemsGrp1[1] = 3;
arrItems1[2] = "列四二";
arrItemsGrp1[2] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[21] = "列4-0";
arrItemsGrp2[21] = 0
arrItems2[22] = "列4-1";
arrItemsGrp2[22] = 0
arrItems2[31] = "列41-0";
arrItemsGrp2[31] = 1
arrItems2[34] = "列41-1";
arrItemsGrp2[34] = 1
arrItems2[35] = "列42-0";
arrItemsGrp2[35] = 2
arrItems2[99] = "列24-2";
arrItemsGrp2[99] = 5
arrItems2[100] = "列24-1";
arrItemsGrp2[100] = 5
arrItems2[57] = "列24-0";
arrItemsGrp2[57] = 5
arrItems2[101] = "列2-0";
arrItemsGrp2[101] = 3
arrItems2[102] = "列2-1";
arrItemsGrp2[102] = 3
arrItems2[103] = "列23-0";
arrItemsGrp2[103] = 4
arrItems2[104] = "列23-1";
arrItemsGrp2[104] = 4
arrItems2[105] = "列3-0";
arrItemsGrp2[105] = 6
arrItems2[106] = "列3-1";
arrItemsGrp2[106] = 6
arrItems2[200] = "列31-0";
arrItemsGrp2[200] = 7
arrItems2[201] = "列31-1";
arrItemsGrp2[201] = 7
arrItems2[203] = "列31-2";
arrItemsGrp2[203] = 7
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement_x("option") ;
myEle.value = 0 ;
myEle.text = "[列表]" ;
controlToPopulate.add(myEle) ;
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement_x("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
<form name=myChoices>
<table align="center">
<tr>
<td>
<SELECT id=firstChoice name=firstChoice onchange="selectChange(this, myChoices.secondChoice, arrItems1, arrItemsGrp1);">
<option value="0">列表一</option>
<option value="1">列表二</option>
<option value="2">列表三</option>
<option value="3">列表四</option>
</SELECT>
</TD><TD>
<SELECT id=secondChoice name=secondChoice onchange="selectChange(this, myChoices.thirdChoice, arrItems2, arrItemsGrp2);">
</SELECT>
<SELECT id=thirdChoice name=thirdChoice>
</SELECT>
</TD>
</TR>
</TABLE>
</form>
希望本文所述对大家的javascript程序设计有所帮助。
您可能感兴趣的文章:
- ASP+JS三级联动下拉菜单[调用数据库数据]
- 全国省市二级联动下拉菜单 js版
- js实现select二级联动下拉菜单
- jquery实现下拉菜单的二级联动利用json对象从DB取值显示联动
- javascript支持区号输入的省市二级联动下拉菜单
- JS实多级联动下拉菜单类,简单实现省市区联动菜单!
- js实现的全国省市二级联动下拉选择菜单完整实例
- 省市区三级联动下拉框菜单javascript版
- javascript实现省市区三级联动下拉框菜单
- jsp从数据库获取数据填充下拉框实现二级联动菜单的方法
- 从QQ网站中提取的纯JS省市区三级联动菜单
- 琥珀无限级联动菜单-JavaScript版
- JS实现经典的中国地区三级联动下拉菜单功能实例【测试可用】
相关文章
javascript操作cookie的文章(设置,删除cookies)
一篇javascript处理cookie的文章,脚本之家之前发布过很多这样的文章。2010-04-04
最新评论