eval("document.all."+str).value = "hello";

解决方案 »

  1.   

    为什么不直接用:
    <script language="JavaScript">
    function hello() {
    document.all.tmp.value="hello";
    }
    </script>
    或者用id来标识
      

  2.   

    <html>
    <head>
    <title>This is a test!</title>
    </head>
    <body><input type=text name=tmp>
    <input type=button value="ok" onclick="hello()"></body>
    </html><script language="JavaScript">
    function hello() {
    str = "tmp";
    document.getElementsByName(str)[0].value="hello";
    }
    </script>
      

  3.   

    <input type=text name=tmp>
    <input type=text name=tmp>
    <input type=text name=tmp>
    <input type=button value="ok" onclick="hello()">
    <script>
    function hello() {
    var str = "tmp";
    for(i=0;i<document.getElementsByName(str).length;i++)
    {
    document.getElementsByName(str)[i].value="hello"+i;
    }
    }
    </script>
      

  4.   

    用eval了
    eval("document.all."+str).value="hello"
      

  5.   

    <html>
    <head>
    <title>This is a test!</title>
    </head>
    <body><input type=text name=tmp>
    <input type=button value="ok" onclick="hello()"></body>
    </html><script language="JavaScript">
    function hello() {
    str = "tmp";
    document.all(str).value="hello";
    }
    </script>
      

  6.   

    也可以这样子.<html>
    <head>
    <title>This is a test!</title>
    </head>
    <body><input type=text name=tmp>
    <input type=button value="ok" onclick="hello()"></body>
    </html><script language="JavaScript">
    function hello() {
    str = "tmp";
    eval("document.all."+str+".value='hello'");
    }
    </script>