在文本框一中输入数字,在文本框二中就显示相对应的内容,
 比如先定义好数组
a1(1,杭州)
a2(2,浙江)
a3(3,温州)我在文本框一中输入  1  ,鼠标离开时 文本框二中就显示 杭州 ,

解决方案 »

  1.   


    <script type="text/javascript">
    var arr={1:'杭州',2:'浙江',3:'温州'};
    window.onload=function(){
       document.getElementById("t1").onblur=function(){
        var t=this.value;
             for (var i in arr)
            {
    if(t==i)document.getElementById('t2').value=arr[i];
            }
     }
    }</script>
    <input type="text" id="t1">
    <input type="text" id="t2">这样不知道是否OK。当文本框1失去焦点,2立刻显示对应的文字!
      

  2.   

    <script language="javascript">
    Citys = new Array(); <% 
    dim rs11,sql,i 
    sql = "select * from dev_xinghao" 
    set rs11 = Conn.execute(sql) 
    i = 0 
    while not rs11.eof 
    %> 
    Citys[<%=i%>] =new Array("<%=rs11("did")%>","<%=rs11("dxinghao")%>"); <% 
    i = i + 1 
    rs11.movenext 
    wend 
    rs11.close 
    set rs11 = nothing 
    %> 
    我想数组内容从数据库里读出来,这样可以?
      

  3.   

    怎么把数据库里的数据存为arr={1:'杭州',2:'浙江',3:'温州'};
    这样的格式?
      

  4.   

    如果要动态从后台取值。可以用ajax
      

  5.   

    <script language = "JavaScript">
    Citys=new Array(); 
    <% 
    dim rs11,sql
      
    sql = "select * from dev_xinghao" 
    set rs11 = Conn.execute(sql) 
    i = 0 
    while not rs11.eof 
    %> 
    Citys[<%=i%>] =new Array("<%=rs11("did")%>","<%=rs11("dxinghao")%>"); 
    <% 
    i = i + 1 
    rs11.movenext 
    wend 
    rs11.close 
    set rs11 = nothing 
    %> 
    function changelocation(locationid){
         
        var locationid=locationid;
        var ii;
    ii=<%=i%>
        for (j=0;j < ii; j++){
            if (Citys[j][0] == locationid){ 
               
            document.form1.Popedom.value=Citys[j][1]
    }    
        }
    }
    </script>
      <input type="text" name="Popedom11" onChange="changelocation(this.value)" >
    <input type="text" name="Popedom">   已解决,谢谢各位