<input id="test1">
<input id="test2">
<input id="test3">
<input id="test4">
<SCRIPT LANGUAGE="JavaScript">
for (var i=1;i<=4;i++)alert(eval("test"+i).id)
</SCRIPT>

解决方案 »

  1.   

    同意楼上
    例如验证表单,input name 为cj0 cj1...
    <script language="javascript">
    <!--
    function check(form)
    {
      var a=Number(form.cj_num.value);//转换成int
       var i;
       for(i=1;i<=a;i++)
       {
       var b="cj"+i;
       alert(document.all(b).value); // var b=eval("form.cj"+i);都可以
     }
     }
    </script>
      

  2.   

    eval 函数允许 JScript 源代码的动态执行
    eval('aaa' + 1).focus(); 相当于:aaa1.focus();
      

  3.   

    eval是用来检查javascript代码并让其执行的一个函数
    所以参数可以是任何对象
      

  4.   

    from MSDN:
    **********************
    [This topic is part of a beta release and is subject to change in future releases. Blank topics are included as placeholders.]Evaluates JScript code and executes it. eval(codeString) 
    The required codeString argument is a string value that contains valid JScript code. This string is parsed by the JScript parser and executed.Res
    The eval function allows dynamic execution of JScript source code. For example, the following code creates a new variable mydate that contains a Date object: eval("var mydate = new Date();");
    The code passed to the eval method is executed in the same context as the call to the eval method.