//colCls----′óàà?ˉo?
//êy?Y??áD·?ê?£o′óààID-′óàà??
var colCls = new Array();
//colSubCls----?ùóDμ?×óàà?ˉo?
//êy?Y??áD·?ê?£o′óààID-×óààID-×óàà??
var colSubCls = new Array();
<%
Set rsClass = SelectQuery(conn,"select * from t_industrycls",True)
nCount = rsClass.RecordCount
For i=0 To nCount
%>
colCls[<%=i%>] = new Array("<%=rsClass("id")%>","<%=trim(rsClass("name"))%>");
<%
rsClass.MoveNext
If rsClass.Eof Then Exit For
Next
CloseObject rsClass
%>
//subclass
<%
Set rsClass = SelectQuery(conn,"t_industrysubcls",True)
nCount = rsClass.RecordCount
For i=0 To nCount
%>
colSubCls[<%=i%>] = new Array("<%=rsClass("clsid")%>","<%=rsClass("id")%>","<%=trim(rsClass("name"))%>");
<%
rsClass.MoveNext
If rsClass.Eof Then Exit For
Next
CloseObject rsClass
%>
/*
oˉêy??£oInitClsCtrl
1|?ü?μ?÷£o
1?¢ó?′óààIDì?3?id?asNameμ?áD±í?ò
2?¢2¢???D′óààáD±í?ò?Dvalue?anSelIdμ?????
2?êy?μ?÷£o
sName------′óààáD±í?òμ???×?
nSelId-----òa???Dμ?′óààID
*/
function InitClsCtrl(sName,nSelId)
{
var oClass;
oClass = document.getElementById(sName);
var nLen = colCls.length;
while (oClass.options.length>0)
{
oClass.options.remove(0);
}
for (var i = 0; i<nLen; i++)
{
var oOption = new Option(colCls[i][1],colCls[i][0]);
oClass.add(oOption);
}
if (arguments.length<2)
oClass.options[0].selected = true;
else
{
nLen = oClass.length;
for (var i = 0; i<nLen; i++)
{
if (oClass.options[i].value==nSelId)
{
oClass.options[i].selected = true;
break;
}
}
}
}
/*
oˉêy??£oInitSubClsCtrl
1|?ü?μ?÷£o
1?¢ó?ê?óú′óààIDμ?×óààì?3?id?asNameμ?áD±í?ò
2?¢2¢???D×óààáD±í?ò?Dvalue?anSelIdμ?????
2?êy?μ?÷£o
sName------×óààáD±í?òμ???×?
nClsId-----′óààID
nSelId-----òa???Dμ?×óààID
*/
function InitSubClsCtrl(sName,nClsId,nSelId)
{
var oSub;
oSub = document.getElementById(sName);
//??′óààID?anClsIdμ?×óàà?óè?áD±í?ò
var nLenCls = colCls.length;
var nLenSub = colSubCls.length;
if (arguments.length<2)
nClsId = colCls[0][0];
while (oSub.options.length>0)
{
oSub.options.remove(0);
}
for (var i=0; i<nLenCls; i++)
{
for (var j=0; j<nLenSub; j++)
{
if (nClsId == colCls[i][0]&&colCls[i][0]==colSubCls[j][0])
{
var oOption = new Option(colSubCls[j][2],colSubCls[j][1]);
oSub.add(oOption);
}
}
}
if (arguments.length<3)
oSub.options[0].selected = true;
else
{
nLen = oSub.length;
//??ID?anSelIdμ?×óàà???D
for (var j=0; j<nLen; j++)
{
if (nSelId == oSub.options[j].value)
{
oSub.options[j].selected=true;
return;
}
}
}
}
表结构:大类: id,name ---------- 子类 id,clsid,name 使用方法:假设大类列表框id为clsid,子类列表框名为subclsid 先初始化列表框 InitClsCtrl("clsid"); InitSubClsCtrl("subclsid"); 大类列表框的onChange="InitSubClsCtrl('subclsid',this.value)"