alert (document.all("txt"+i).value)

解决方案 »

  1.   

    obj=eval('form1.txt'+i);
    alert(obj.value)
      

  2.   

    笔误:(应该是:<form name=form1>
    <input name=txt1 value=1>
    <input name=txt2 value=2>
    <input name=txt3 value=3>
    <input name=txt4 value=4>
    </form>
    <script language="javascript">
    function chk(){
    var s;
    for(i=1;i<5;i++)
                      {  
                              s='txt'+i;
            alert(eval("form1."+ s + ".value"));                  }
    }
    chk();
    </script>