<script language="javascript">
<!--
  function fncchange(strv)
  {
    var o = document.all.s2;
    for(var i=0;i<o.length;i++)
    {
      if(o.options[i].text.substr(o.options[i].text.length-2,2) == strv)
        o.options[i].selected = true;
    }
  }
//-->
</script><select name=s1 onchange="fncchange(this.value);">
<option value=01>mm
<option value=02>cc
<option value=03>44
</select>
<select name=s2>
<option value=001>xx01
<option value=002>xxx02
<option value=003>sdfa03
</select>

解决方案 »

  1.   

    <script language="javascript">
    <!--
      function fncchange(strv)
      {
        var o = document.all.s2;
        for(var i=0;i<o.length;i++)
        {
          if(o.options[i].value.substr(o.options[i].value.length-2,2) == strv)
            o.options[i].selected = true;
        }
      }
    //-->
    </script><select name=s1 onchange="fncchange(this.value);">
    <option value=01>mm
    <option value=02>cc
    <option value=03>44
    </select>
    <select name=s2>
    <option value=001>xx
    <option value=002>xxx
    <option value=003>sdfa
    </select>
      

  2.   

    楼主,这样说的话,你不觉得题目出得有问题吗,既然不能"01"和"001"对应,也不能含有"01",那我想问一句,xx    (01)
    xxx   (02)
    sdfa  (03)这种关系是怎么建立起来的,请解释一下,不明白原理没法找到答案~~~
      

  3.   

    我的解决方法(自己用过,也是从数据库中读取)1、先从数据库中读取select1所需要的数据
    2、通过循环从数据库中读取与select1所对应的选项数据
    3、调用的时候,把这些数值传给一段js代码,比如changeselect(str1,str2,selectvalue)
    4、在js代码中分解这两个字符串,并做成数据
    5、通过传递过来的selectvalue判断所对应的组数
    6、通过js改变select2的列表内容
      

  4.   

    你还是研究一下这个吧
    <% 
    dim conn,constr
    constr="driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="& server.mappath("class.mdb")
    set conn=server.createobject("adodb.connection") 
    conn.open constrset rs=server.createobject("adodb.recordset")
    rs.open "select * from school order by anclassid",conn,1,1%>
    <script language = "JavaScript">
    var onecount;
    onecount=0;
    subcat = new Array();
    <%
       count = 0
       do while not rs.eof 
    %>
    subcat[<%=count%>] = new Array("<%= trim(rs("anclassid"))%>","<%= rs("anclass")%>","<%= rs("nclass")%>");
    <%
            count = count + 1
            rs.movenext
            loop
            rs.close
    %>

    onecount=<%=count%>;function changelocation(locationid)
        {
        document.form.Nclassid.length = 0;     var locationid=locationid;
        var i;
        for (i=0;i < onecount; i++)
            {
                if (subcat[i][0] == locationid)
                { 
                 document.form.Nclassid.options[document.form.Nclassid.length] = new Option(subcat[i][2], subcat[i][2]);
                }        
            }
            
        }    
    </script>
    <%
    set rs=server.createobject("adodb.recordset")
    rs.open "select distinct anclassid,anclass from school order by anclassid",conn,1,1
    if rs.eof and rs.bof then
    response.write "请先添加栏目。"
    response.end
    else
    %>
    <form name="form">
    <select name="anclassid" size="1" id="class" onChange="changelocation(document.form.anclassid.value)">
    <option selected value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
    <% dim selclass
             selclass=rs("anclassid")
            rs.movenext
            do while not rs.eof
    %> 
    <option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
    <%
            rs.movenext
            loop
    end if
            rs.close
    %> 
    </select>
    <select name="Nclassid">
     <%rs.open "select * from school where anclassid="&selclass ,conn,1,1
    if not(rs.eof and rs.bof) then
    %> 
     <option selected value="<%=rs("nclass")%>"><%=rs("nclass")%></option>
     <% rs.movenext
    do while not rs.eof%> 
    <option value="<%=rs("nclass")%>"><%=rs("nclass")%></option>
    <% rs.movenext
    loop
    end if
            rs.close
            set rs = nothing
    %> 
     </select>
     </form>