请问大家这个javascript怎样写?
<html>
  <head>
 <script language="javascript">
 
  function newUpload(){
    //怎样能得到file1的框中的值  ?????
  }
 </script>
  </head>
  <body>
    <table>
      <input type="file" name="file1" value="a">
      <input type="button" name="new" value="new" onclick="javascript:newUpload();">
<span id="p"></span>
    </table>
  </body>
</html>

解决方案 »

  1.   

    function   newUpload(){ 
            alert(document.all.file1.value);
        }
      

  2.   

    document.getElementsByName(file1).value
      

  3.   

    document.all.file1.value
    就是它的值啊.
    因为安全方面的考虑,file类型中的value的值是不让写死的.所以如果你是想取的值是你写的"a"
    那是不可能的.(黑客应该有办法)
      

  4.   

    <html>
    <head>
    <script>
     function check()
     {
         //alert(document.form[1].file1.value);
         alert(window.document.form1.file1.value);
     }
    </script>
    </head>
    <body>
     <form name="form1">
          <input       type="file"       name="file1"> 
          <input type="button" value ="aaaa" onclick="return check();">
    </form>
    </body>
    </html>
      

  5.   

    最兼容的方法。这样可以在 id  ff o s 等浏览器使用。 写js 脚本请注意 兼容性问题。
    在页面上获取dom 最好用id 还有注意 标签的id不要同名,如果要同名 请设置name(这一般用于多选控件)
    再推介一个web页面工具 :aptana
    <html> 
      <head> 
      <script   language="javascript">   
        function   newUpload(){ 
           alert(document.getElementById("file").value);
        } 
      </script> 
        </head> 
        <body> 
            <table> 
               <tr><td>
                <input   type="file"   name="file1"   value="a"> 
                <input   type="button"   name="new"   value="new"   onclick="newUpload();"> 
               </td></tr>
            </table> 
        </body> 
    </html> 
      

  6.   

    如果用document.getElementById(),里面应该加双引号
    document.getElementById("file1").value;
    或者document.all.file1.value;
    都可以取到的,兄弟!~