日期:2014-05-16 浏览次数:20985 次
<select name="bid" id="bid" onchange="initSid(this.value)">
<%
bid="111"'需要初始化的大类id
ss="var sidarr={};"'小类JSON字符串
while not rs1.eof
rs2.Filter="classid="&rs1("classid")'过滤得到小类数据,生成JSON数组
temp=""
while not rs2.eof
temp="{id:"&rs2("Lclassid")&",t:'"&rs2("Lclassname")&"'},"
rs2.movenext
wend
if temp<>"" then temp=left(temp,len(temp)-1)'去掉最后一个,
ss=ss&"sidarr['k"&rs1("classid")&"']=["&temp&"];"'大类对应的小类的JSON数组
if bid=rs1("classid") then
%>
<option value="<%=rs1("classid") %>" selected><%=rs1("classname") %></option>
<%
else
%>
<option value="<%=rs1("classid") %>"><%=rs1("classname") %></option>
<%
end if
rs1.movenext
wend
%>
</select>
<select name="sid" id="sid"></select>
<script>
<%=ss %>//小类JSON数组
var bid=document.getElementById('bid').value,sid='<%=sid %>'//需要初始化的小类id
function initSid(bid){
var sid=document.getElementById('sid'),selectedIndex=-1;
sid.options.length=0;
var arr=sidarr['k'+bid];
for(var i=0;i<arr.length;i++){
sid.options.add(new Option(arr[i].t,arr[i].id));
if(arr[i].id.toString()==sid)selectedIndex=i;
}
if(selectedIndex!=-1)sid.selectedIndex=selectedIndex;
}
initSid(bid)
</script>
<%
Dim json,subcls,sql,rs,sql1,rs1
set rs=server.createobject("adodb.recordset")
sql = "select classid,ClassName from class"
rs.open sql,conn,1,1
do while not rs.eof
json = json &",{id:"&rs(0)&",name:'"&rs(1)&"',subclass:["
subcls="{id:'',name:'不指定小类'}"
set rs1=server.createobject("adodb.recordset")
sql1="select SmallClassid,SmallClassName from SmallClass where Classid=" & rs(0)
rs1.open sql1,conn,1,1
do while not rs1.eof
subcls=subcls&",{id:"&rs1(0)&",name:'"&rs1(1)&"'}"
rs1.movenext
loop
rs1.close:Set rs1 = Nothing
json = json &subcls&"]}"
rs.movenext
Loop
rs.close:Set rs = Nothing
call connclose()
%>