<script>ec(2);</script> <% response.write "<select name=""class_id"" onChange=""classselect(this);"">"&vbCrlf strJS="function classselect(obj){for (var i=document.refer.class_c_id.options.length;i>=0;i--){document.refer.class_c_id.options[i]=null;"&vbCrlf '清除原有option对象的JS代码 sql="select class_id,class_name from class order by class_order" set rs=conn.execute(sql) while not rs.eof response.write "<option value="&rs("class_id") if class_id<>"" then if rs("class_id")=CInt(class_id) then '使相对应的父类的option上为selected。一定加CInt函数,否则不行 response.write " selected " end if end if response.write ">"&rs("class_name")&"</option>"&vbCrlf strJS=strJS&"}"&vbCrlf&"if (obj.options[obj.selectedIndex].value=="&rs("class_id")&"){"&vbCrlf sql1="select class_c_id,class_c_name from class_c where class_id="&rs("class_id")&" order by class_c_order" set rs1=conn.execute(sql1) while not rs1.eof strJS=strJS&"document.refer.class_c_id.options[document.refer.class_c_id.options.length]=new Option('"&rs1("class_c_name")&"','"&rs1("class_c_id")&"');"&vbCrlf rs1.movenext wend rs.movenext wend '为了使第一个子类的option不为空==================================================== if class_id="" then sql="select class_id,class_name from class" set rs=conn.execute(sql) sql="select class_c_id,class_c_name from class_c where class_id="&rs("class_id")&" order by class_c_order" else sql="select class_c_id,class_c_name from class_c where class_id="&class_id&" order by class_c_order" end if set rs=conn.execute(sql) while not rs.eof if class_c_id<>"" then if rs("class_c_id")=CInt(class_c_id) then '使相对应的子类的option上为selected。if放在字符串连接前面 strJS3="var option_length=document.refer.class_c_id.options.length;"&vbCrlf strJS2="document.refer.class_c_id.options[option_length].selected=true;"&vbCrlf else strJS3="" end if end if strJS1=strJS1&strJS3&"document.refer.class_c_id.options[document.refer.class_c_id.options.length]=new Option('"&rs("class_c_name")&"','"&rs("class_c_id")&"');"&vbCrlf rs.movenext wend '================================================================================== strJS=strJS&"}"&vbCrlf&"}"& vbCrlf response.write " </select>" response.write "<select name=""class_c_id"">" response.write "</select>" response.write "<script language=""JavaScript"">"&vbCrlf '输出JS脚本 response.write strJS1&vbCrlf&strJS2&vbCrlf response.write strJS&"</SCRIPT>"&vbCrlf conn.close set conn=nothing %>
|