document.getElementById("MyFile")和insertAdjacentHTML
("beforeEnd", str)的含义和用法收藏
新一篇: 解决WIN2003因为限制ASP上传最大数值的方法 | 旧一篇: Web形式实现上传文件
document.getElementById("MyFile")为:获得名称为MyFile的层。
insertAdjacentHTML("beforeEnd", str)为:
MyFile层在其后追加插入内容为 INPUT type="file" size="50" NAME="File"> 的html格式信息。
向下面的例子,可以拷贝到网页中试试:
<script language="JavaScript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File">'
document.getElementById("MyFile").insertAdjacentHTML("beforeEnd", str)
}
</script>
<div id="MyFile">
1234567
</div>dfdfdfdf
<a href="javascript:addFile()">df</a>
发表于 @ 2006年05月25日 20:49:00|评论(0 )|编辑
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class AddNews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
this.BindNewsKind();
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
string NewsTitle = this.TxtNewsTitle.Text;
int NewsKindId = Convert.ToInt32(this.DropNewsKinds.SelectedValue);
string NewsBody = this.WebNewsBody.Text;
DateTime PubTime = DateTime.Now;
int UserId = Users.GetUserIdByUserName(Session["UserName"].ToString());
News SingleNews = new News();
SingleNews.NewsTitle = NewsTitle;
SingleNews.NewsKindId = NewsKindId;
SingleNews.NewsBody = NewsBody;
SingleNews.PubDate = PubTime;
SingleNews.UserId = UserId;
if (News.AddNews(SingleNews))
{
this.LabMessage.Text = "添加成功!";
}
else
{
this.LabMessage.Text = "添加失败";
}
}
public void BindNewsKind()
{
this.DropNewsKinds.DataSource = NewsKinds.GetAllNewsKinds();
this.DropNewsKinds.DataTextField = "KindName";
this.DropNewsKinds.DataValueField = "KindId";
this.DropNewsKinds.DataBind();
this.DropNewsKinds.SelectedIndex = 0;
}
protected void BtnCreatHtml_Click(object sender, EventArgs e)
{
string NewsTitle = this.TxtNewsTitle.Text;
string NewsKindName = this.DropNewsKinds.SelectedItem.Text;
string NewsBody = this.WebNewsBody.Text;
DateTime PubTime = DateTime.Now;
string UserName = Session["UserName"].ToString();
Response.Write(NewsKindName);
string[] strNewsHtml = new string[]{NewsTitle,NewsKindName,NewsBody,PubTime.ToString(),UserName};
string[] strOldHtml = new string[] { "@Title", "@NewsKInd", "@NewsBody", "@PubTime", "@UserName" };
string strFileName=DateTime.Now.ToString("ddhhmmss")+".html";
string strFilePath = string.Format("NewsHtml/{0}",strFileName);
try
{
if (Files.CreatHtmlPage(strNewsHtml, strOldHtml, "mode.htm", strFilePath))
{
this.LabMessage.Text = "生成成功!";
}
else
{
this.LabMessage.Text = "生成失败!";
}
}
catch
{
this.LabMessage.Text = "生成失败!";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] strNewsHtml=new string[]{"看看我们生成的首页"};
string[] strStartHtml=new string[]{"<!-- StartBody-->"};
string[] strEndHtml=new string[]{"<!-- BodyEnd-->"};
if (Files.UpdateHtmlPage(strNewsHtml, strStartHtml, strEndHtml, "NewsHtml/20074442.html"))
{
this.LabMessage.Text = "更新首页成功!";
}
else
{
this.LabMessage.Text = "更新首页失败!";
}
}
protected void BtnFileUp_Click(object sender, EventArgs e)
{ if (FileUpload1.HasFile)
{
string FileName = FileUpload1.FileName;
string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
string[] NoExPrentFile = new string[] { "exe", "asp", "php" };
bool IsUp = true;
for (int i = 0; i < NoExPrentFile.Length;i++ )
{
if(strExPrentFile.Equals(NoExPrentFile[i]))
{
IsUp = false;
}
}
if(IsUp)
{
string sFilePath = string.Format("files/{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile);
FileUpload1.SaveAs(Server.MapPath(sFilePath));
this.LabMessage.Text = "文件上传成功!" + "<br />文件名是:" + string.Format("{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile) + "<br />文件的格式:" + strExPrentFile;
}
else
{
this.LabMessage.Text = string.Format("不允许上传{0}格式文件", NoExPrentFile);
}
}
else
{
this.LabMessage.Text = "不能上传空文件";
}
}
protected void BtnUpFiles_Click(object sender, EventArgs e)
{
StringBuilder strMessage = new StringBuilder();
HttpFileCollection Files = HttpContext.Current.Request.Files;
for (int i = 0; i < Files.Count;i++ )
{
HttpPostedFile PostedFile = Files[i];
if (PostedFile.ContentLength>0)
{
string FileName = PostedFile.FileName;
string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
string[] NoExPrentFile = new string[] { "exe", "asp", "php" };
bool IsUp = true;
for (int j = 0; j < NoExPrentFile.Length; j++)
{
if (strExPrentFile.Equals(NoExPrentFile[j]))
{
IsUp = false;
}
}
if (IsUp)
{
string sFilePath = string.Format("files/{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile);
PostedFile.SaveAs(Server.MapPath(sFilePath));
strMessage.Append("文件上传成功!");
strMessage.Append(string.Format("{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile));
strMessage.Append("<br />");
strMessage.Append("文件的格式:");
strMessage.Append(strExPrentFile);
strMessage.Append("<br />```````````````<br />");
//this.LabMessage.Text = "文件上传成功!" + "<br />文件名是:" + string.Format("{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile) + "<br />文件的格式:" + strExPrentFile;
}
else
{
//this.LabMessage.Text = string.Format("不允许上传{0}格式文件", NoExPrentFile);
}
}
else
{
//this.LabMessage.Text = "不能上传空文件";
}
}
this.LabMessage.Text = strMessage.ToString();
}
protected void BtnShow_Click(object sender, EventArgs e)
{
string FileName = "00112145.ppt";
string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
string[] NoExPrentFile = new string[] { "jpg", "fig", "jpeg","bmp" };
bool IsUp = false;
for (int j = 0; j < NoExPrentFile.Length; j++)
{
if (strExPrentFile.Equals(NoExPrentFile[j]))
{
IsUp = true;
}
}
if (IsUp)
{
// this.LabMessage.Text = "文件上传成功!" + "<br />文件名是:" + string.Format("{0}.{1}", DateTime.Now.ToString("mmhhddss"), strExPrentFile) + "<br />文件的格式:" + strExPrentFile;
this.LabFile.Text = string.Format("<img src='files/{0}' />",FileName);
}
else
{
this.LabFile.Text = string.Format("<a href='files/{0}'>{1}</a>",FileName,FileName);
}
}
}
分享到:
相关推荐
用Ext编写的多文件上传组件,已封装。 支持多文件上传,文件下载,文件删除,
java多文件上传实现,上传界面采用flash,同时显示上传进度条
说明:支持多文件上传的上传类 使用方法: include '../UploadFile.class.php'; $upload=new UploadFile(); if(!$upload->upload()) { // 上传错误提示错误信息 $this->error($upload->getErrorMsg()); }else{ ...
ajaxfileupload.js 这是个非常好的异步上传图片的插件,来解决form表单上传时要刷新页面的问题。支持多文件上传
使用普通表单的input框,引入多文件上传插件,传报文格式的参数,表单内容同时提交
bootstrap-fileinput-master多文件上传,多文件预览,网页的代码地址为https://mp.csdn.net/postedit/84098479
文件上传比较多,多文件上传少一点 文件下载很少的,看似简单,实则不然 网上的Struts2进行的文件下载一般都是单文件或者固定的文件,并没有(很少)实现随意文件的下载的例子 提供多文件上传,上传成功后,提供...
C#多服务器多文件上传实例,并发,集群对考虑在内
利用flash上传工具,结合jsp来进行多文件上传demo。 能一次性的选择多个文件,有上传进度显示;java项目
.net MVC 实现多文件上传,显示上传进度条,可传多个文件
html5和js多文件上传插件。可任意多文件选择上传,每个文件都可以显示进度,同时可以显示整体进度。采用了html的file对象和blob对象的属性和方法。
C# .NET FileUpload 多文件上传例子,两个方法和思路,适合初学者学习。
完全可运行的Ext多文件上传,带上传速率、进度条等
dhtmlxVault多文件上传dhtmlxVault多文件上传dhtmlxVault多文件上传
swfupload多文件上传带进度条实例,vs2012开发,net4.0框架,可上传多个文件,上传类型、上传大小、上传数量可控,已测试成功!
COS框架实现上传,稍加修改即可实现多文件上传,希望各位采纳
C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载C# 多文件上传下载
uploadify多文件上传例子代码,jsp+servlet实现
SpringMVC单文件上传、多文件上传、文件列表显示、文件下载,具体效果和过程看博文http://blog.csdn.net/evankaka/article/details/45826697