找出了多文件上传的方法和判定文件格式的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>
但如何加入呢?请高手现身!!
多文件上传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>
但如何加入呢?请高手现身!!
解决方案 »
- 如何关闭页面
- 调试运行结果与正常运行结果不同,为何string保存不了数据
- 有没有这样可供借鉴的模块?动态显示cpu,内存使用率。
- 请问css要怎么学比较好呢?
- 求救!Silverlight中关于TextBox 获得空格的问题
- dropdownlist的问题我实现了ajax不刷新更新数据,但是我怎么用ddldownlist.selectValue;服务器的方法来获取ddldownlist.选中的值呢
- vs2005向ACCESS插入数据操作(桌面程序)??
- 用jmail无法发送邮件,显示错误,帮帮忙!!!!
- 关于dropdownlist下拉框的三级联动和后台代码整合
- 有关用存储过程来创建EXCEL的问题(请wzsswz、pingguo_yu等高手帮忙解决)。
- 为什么 web form提交不了?求救 !
- 请高手进来看看 关于DataList的问题 在线等解决立即100分相送
上传文件的button中加上onclick=处理函数 就可以了
比如: <input type="button" value="增加(Add)" onclick="addFile()">
而对于其他客户端按钮,直接在HTML标签里面加入onclick事件就可以了,<input type="button" value="增加(Add)" onclick="addFile()">
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)" >
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()");
上传文件大小在web.config里设置
<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=""
}
}
《
<INPUT id="myFile" type="file" onchange="checkData()" size="34" runat="server">