<html>
<head>
<script language="JavaScript">
<!--function sendsub(){
if(document.f6.sg.checked){
if (confirm("确定要覆盖上传吗?")){
setTimeout("document.f6.sg.checked=false;",999);
return true;
}
}else{
if(confirm("确定要上传吗?")){
return true;
}
}
return false;
}
var nfiles = 1;
function Expand(){
nfiles++;
if (nfiles>9) {
alert("每次上传最好小于10个文件");
}else {
file.insertAdjacentHTML('BeforeEnd','<br>文件'+nfiles+' <input type="file" name="File'+nfiles+'" size=23 class=fileput>');
}
self.document.f6.file_num.value=nfiles;
return false;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" rightmargin=0 leftmargin=0 topmargin=0>
<table width="96%" border="0" cellspacing="2" cellpadding="2" align="center">
        <form action="upload.php" enctype="multipart/form-data" method="post" onSubmit="return sendsub();" name="f6">
          <tr bgcolor="#AC9988"> 
          <td height="20"><a onClick="return Expand();" style="cursor:hand">增加文件</a>
          </td>
  </tr>
          <tr bgcolor="#E7E1DC">
            <td>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td> 
                    <div id=file>文件1 
                      <input type="file" name="File1" class=fileput size="23">
                    </div>
                  </td>
                </tr>
              </table>
          </td></tr>
          <tr bgcolor="#E7E1DC"><td>
<input type=hidden name='file_num' value=1>
                    <input type="submit" value="开始上传" class=btn name="submit">
            </td>
          </tr>
        </form>
</table></body>
</html>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
    function addRow()
    {
     var row = tab1.insertRow(0); 
     for(i=0;i<tab1.rows[1].cells.length;i++)
    {
    cell = row.insertCell(i);
    cell.innerHTML = "<input name=text" +  i + ">";
    }
    }</script>
    </head><body>
    <table id=tab1 width="300" border="1" cellpadding="5" cellspacing="0">
      <tr>
        <td width="100">&nbsp;</td>
        <td width="79">&nbsp;</td>
        <td width="83">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <p>
      <input type="button" name="Button" value="Button" onClick="addRow()">
    </p>
    <p></p>
    </body>
    </html>
      

  2.   

    请教 myblessu(寒飞) :
        不知道 insertAdjacentHTML 我该怎么理解?
      

  3.   

    呵呵,to  fzel_net(kenshin)PFPF,先知啊
      

  4.   

    呵呵.我也同意fason的
    好玩
      

  5.   

    tzjfoo(难道是真的?) 查MS的说明如下:insertAdjacentHTML MethodInserts the given HTML text into the element at the location.Syntaxobject.insertAdjacentHTML(sWhere, sText)
    ParameterssWhere Required. String&Acirc; that specifies where to insert the HTML text, using one of the following values: beforeBegin Inserts sText immediately before the object. 
    afterBegin Inserts sText after the start of the object but before all other content in the object. 
    beforeEnd Inserts sText immediately before the end of the object but after all other content in the object. 
    afterEnd Inserts sText immediately after the end of the object. 
     
    sText Required. String&Acirc; that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail. Return ValueNo return value.ResIf the text contains HTML tags, the method parses and formats the text as it is inserted.You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element. ExampleThis example uses the insertAdjacentHTML method to insert script into the page.var sHTML="<input type=button onclick=" + 
        "go2()" + " value='Click Me'><BR>"
    var sScript='<SCRIPT DEFER>'
    sScript = sScript + 
        'function go2(){ alert("Hello from inserted script.") }'
    sScript = sScript + '</script' + '>';
    ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);
    Show Me
    Standards InformationThere is no public standard that applies to this method. 
      

  6.   

    GZ,
    顺便问一下,如何点这个Button后让变量加1后返回
    就是说我的input的name是这样的:表格所在的行号_列号,点击Button的时候传过去行号,但如何实现返回来的时候行号已经加1了呢
      

  7.   

    up, myblessu(寒飞)的例子不错~
    <html>
    <head>
    <script language="JavaScript">
    <!--function sendsub(){
    if(document.f6.sg.checked){
    if (confirm("确定要覆盖上传吗?")){
    setTimeout("document.f6.sg.checked=false;",999);
    return true;
    }
    }else{
    if(confirm("确定要上传吗?")){
    return true;
    }
    }
    return false;
    }
    var nfiles = 1;
    function Expand(){
    nfiles++;
    if (nfiles>9) {
    alert("每次上传最好小于10个文件");
    }else {
    file.insertAdjacentHTML('BeforeEnd','<br/>文件'+nfiles+' <input type="file" name="File'+nfiles+'" size=23 class=fileput>');
    }
    self.document.f6.file_num.value=nfiles;
    return false;
    }
    //-->
    </script>
    </head>
    <body bgcolor="#FFFFFF" text="#000000" rightmargin=0 leftmargin=0 topmargin=0>
    <table width="96%" border="0" cellspacing="2" cellpadding="2" align="center">
            <form action="upload.php" enctype="multipart/form-data" method="post" onSubmit="return sendsub();" name="f6">
              <tr bgcolor="#AC9988"> 
              <td height="20"><a onClick="return Expand();" style="cursor:hand">增加文件</a>
              </td>
      </tr>
              <tr bgcolor="#E7E1DC">
                <td>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td> 
                        <div id=file>文件1 
                          <input type="file" name="File1" class=fileput size="23">
                        </div>
                      </td>
                    </tr>
                  </table>
              </td></tr>
              <tr bgcolor="#E7E1DC"><td>
    <input type=hidden name='file_num' value=1>
                        <input type="submit" value="开始上传" class=btn name="submit">
                </td>
              </tr>
            </form>
    </table></body>
    </html>