找出了多文件上传的方法和判定文件格式的JavaScript代码,但是如何加呢.
多文件上传HTML代码如下:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MultiUpload.aspx.vb"
 Inherits="aspxWeb.MultiUpload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <title>多文件上传</title>
    <script language="JavaScript">
    function addFile()
    {
     var str = '<INPUT type="file" size="50" NAME="File">'
     document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
    }
    </script>
  </HEAD>
  <body>
    <form id="form1" method="post" runat="server" enctype="multipart/form-data">
      <center>
        <asp:Label Runat="server" ID="MyTitle"></asp:Label>
        <P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
        <P>
          <input type="button" value="增加(Add)" onclick="addFile()">
          <asp:Button Runat="server" Text="上传" ID="Upload"></asp:Button>
          <input onclick="this.form.reset()" type="button" value="重置(ReSet)">
        </P>
      </center>
      <P align="center">
        <asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True"
         Font-Size="9pt" Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
      </P>
    </form>
  </body>
</HTML>
如果不是JGP或GIF格试的文件,应弹出一个对话框,然后跳出来,代码如下:
Script language="javascript">
function mysubmit(theform)
{
    if(theform.picsrc.value=="")
    {
    alert("请点击浏览按钮,选择您要上传的jpg或gif文件!")
    theform.picsrc.focus;
    return (false);
    }
    else
    {
    str= theform.picsrc.value;
    strs=str.toLowerCase();
    lens=strs.length;
    extname=strs.substring(lens-4,lens);
    if(extname!=".jpg" && extname!=".gif")
    {
    alert("请选择jpg或gif文件!");
    return (false);
    }
    }
    return (true);
}
</script>
但如何加入呢?请高手现身!!

解决方案 »

  1.   

    什么如何加入??
    上传文件的button中加上onclick=处理函数   就可以了
     比如: <input type="button" value="增加(Add)" onclick="addFile()">
      

  2.   

    在 PAGE_LOAD 里写Upload.Attributes.Add("onclick", "return mysubmit(this.form)")
      

  3.   

    对于服务器段按钮控件,需要使用按钮对象.Attributes.Add("onclick", "js事件")
    而对于其他客户端按钮,直接在HTML标签里面加入onclick事件就可以了,<input type="button" value="增加(Add)" onclick="addFile()">
      

  4.   

    加入到上传按钮的onclick的事件当中呀
      

  5.   

    <!--
      
    function CheckForm(theform){
    if (theform.txtPicture.value.length <1)
    {alert("请选择上传的文件!");
     theform.txtPicture.focus();
     return false;}
     if (theform.txtPicture.value.substring(theform.txtPicture.value.length-3).toLowerCase()!="jpg"&&theform.txtPicture.value.substring(theform.txtPicture.value.length-3).toLowerCase()!="swf"&&theform.txtPicture.value.substring(theform.txtPicture.value.length-3).toLowerCase()!="gif")
    {
     alert("系统只支持上传jpg/gif/swf文件!");
     theform.txtPicture.focus();
     return false;
     }
    return true;
    }// -->
    <form id="Form1" method="post" runat="server" enctype="multipart/form-data" onSubmit="return CheckForm(this)" >
      

  6.   

    <script language="javascript">
    function checkFile()
    { var type,filePath;

    filePath=fileForm.file.value; if (type=filePath.lastIndexOf("jpg")>0)
    {
    document.img.src=filePath;
    return true;
    }
    else if(type=filePath.lastIndexOf("gif")>0)
    {
    document.img.src=filePath;
    return true;
    }
    else
    {
    document.fileForm.file.value="";
    alert('只支持gif,jpg的格式');
    return false;
    }
    //if(!)
    }
    </script>
    下边的代码要自己改一下.
    <input type="file" name="file" onChange="checkFile()" value=""> 
    大概是这个样子
    Upload.Attributes.Add("onChange",reutrn checkFile()");
      

  7.   

    都说了,接分
    上传文件大小在web.config里设置
      

  8.   

    我用客户端的File Field上传图片,判断图片的后缀名,和你的上传文件的原理一样
    <script>
    function checkData()
    {
    var fileName=document.getElementById("myFile").value;
    if(fileName=="")
    return;
    var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
    //alert(exName)
    if(exName=="JPG"||exName=="BMP"||exName=="GIF")
    {
    document.getElementById("myimg").src=fileName
    }
    else
    {
    alert("请选择正确的图片文件")
    document.getElementById("myFile").value=""
    }
    }
      

  9.   

    还有下面的一段
    <INPUT id="myFile" type="file" onchange="checkData()" size="34" runat="server">