js进度条?html5进度条怎么写
尊敬的读者,js进度条和html5进度条怎么写是当前备受关注的话题,但许多人对其仍存在疑惑。在本篇文章中,我将为你提供清晰的解释和深入的分析,希望能满足你的求知欲望。
html5进度条怎么写
首先,我们制作的这个进度条并没有后台数据作为支撑,所以是一个靠js实现的一个简单的页面。
我们首先需要新建一个html5的页面,其使用的progress元素实在html5时代才出现的。
我们在新建的页面中,输入一个段落标签,一个进度条,一个button按钮。
然后,我们需要设置一下进度条显示的进度。value代表从多少开始,max代表到多少结束。我们做的是百分比形式的,应该写成这样的。
这些做好之后,我们需要书写两个小的事件,实现原理大体上是鼠标单击下载按钮,开始下载变为正在下载百分之多少,等到达到我们预设的时间后显示下载完成。
我们之前已经给p标签和progress标签分别赋予了不同的id,我们需要获取到这两个元素,并将他们赋给两个变量。
我们还要将progress的初始值设为0,当鼠标单击的时候,我们以一定的时间为周期调用写好的事件。
函数写好之后,我们在浏览器中调试,点击下载按钮之后会在300ms内完成下载时间。
C#中怎样实现进度条的效果
页面:
<script language="javascript">
function checkFile(source, arguments)
{
arguments.IsValid=(document.all["theFile"].value!="");
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
<P><STRONG>
<asp:HyperLink id="lnkReload" runat="server" NavigateUrl="FileProcessBar.aspx" Font-Bold="True">重新载入页面</asp:HyperLink></STRONG></P>
<P></P>
<asp:Panel id="panUpload" runat="server" Width="550px">
<P>请选择你要上载的文件:</P>
<P>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="80%" align="center" border="0">
<TR>
<TD align="right" width="50">文件:</TD>
<TD><INPUT id="theFile" style="WIDTH: 100%" type="file" name="theFile" runat="server">
</TD>
</TR>
<TR>
<TD align="right" width="50"></TD>
<TD>
<asp:CustomValidator id="cusValTheFile" runat="server" ClientValidationFunction="checkFile" Display="Dynamic"
ErrorMessage="你必须选择你上载的<b>文件</b>。"></asp:CustomValidator></TD>
</TR>
<TR>
<TD align="right" width="50"></TD>
<TD>
<asp:TextBox id="edInfo" runat="server" Width="100%"></asp:TextBox></TD>
</TR>
<TR>
<TD align="right" width="50"></TD>
<TD>
<asp:RequiredFieldValidator id="reqValInfo" runat="server" Display="Dynamic" ErrorMessage='文件的"<b>描述</b>"不能为空,请输入一些信息。'
ControlToValidate="edInfo"></asp:RequiredFieldValidator></TD>
</TR>
<TR>
<TD align="right" width="50"></TD>
<TD>
<asp:CheckBox id="chbImportant" runat="server" Text="重要"></asp:CheckBox></TD>
</TR>
<TR>
<TD align="right" width="50"></TD>
<TD>
<asp:Button id="btnUpload" runat="server" Width="64px" Text="上载"></asp:Button></TD>
</TR>
</TABLE>
<BR>
</P>
</asp:Panel>
<asp:Panel id="panInfo" runat="server" Width="550px">
<P>
<asp:LinkButton id="btnRefresh" runat="server" Visible="False">上载图像...</asp:LinkButton></P>
<P>
<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="80%" align="center" border="0">
<TR>
<TD align="right" width="100">文件名称:</TD>
<TD>
<asp:Label id="lblFilename" runat="server" Font-Bold="True"></asp:Label></TD>
</TR>
<TR>
<TD align="right" width="100">进程条:</TD>
<TD>
<asp:Label id="lblProgress" runat="server" Font-Bold="True"></asp:Label></TD>
</TR>
<TR>
<TD style="HEIGHT: 16px" align="right" width="80"></TD>
<TD style="HEIGHT: 16px">
<asp:Panel id="panProgressBar" runat="server" BackColor="#404040"></asp:Panel></TD>
</TR>
<TR>
<TD align="right" width="80"></TD>
<TD>
<asp:Button id="btnCancel" runat="server" Width="64px" Text="取消"></asp:Button></TD>
</TR>
</TABLE>
</P>
</asp:Panel>
<asp:Panel id="panResult" runat="server" Width="550px">
<P>
<asp:Label id="lblResult" runat="server"></asp:Label></P>
<P>
<asp:HyperLink id="lbkReturn" runat="server" NavigateUrl="FileProcessBar.aspx">返回上载页面</asp:HyperLink></P>
</asp:Panel>
<asp:Literal id="litRefreshJS" runat="server"></asp:Literal>
</form>
</body>
后台代码:
public class FileProcessBar: System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink lnkReload;
protected System.Web.UI.WebControls.CustomValidator cusValTheFile;
protected System.Web.UI.WebControls.TextBox edInfo;
protected System.Web.UI.WebControls.RequiredFieldValidator reqValInfo;
protected System.Web.UI.WebControls.CheckBox chbImportant;
protected System.Web.UI.WebControls.Button btnUpload;
protected System.Web.UI.WebControls.Panel panUpload;
protected System.Web.UI.WebControls.LinkButton btnRefresh;
protected System.Web.UI.WebControls.Label lblFilename;
protected System.Web.UI.WebControls.Label lblProgress;
protected System.Web.UI.WebControls.Panel panProgressBar;
protected System.Web.UI.WebControls.Button btnCancel;
protected System.Web.UI.WebControls.Panel panInfo;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.WebControls.HyperLink lbkReturn;
protected System.Web.UI.WebControls.Panel panResult;
protected System.Web.UI.WebControls.Literal litRefreshJS;
protected System.Web.UI.HtmlControls.HtmlInputFile theFile;
// determin how often Progress Info will be refreshed
const int RefreshTime= 2000;
// determine, which panel to show
public enum PageMode{ UploadForm, Uploading, Result}
public PageMode pageMode
{
get
{
object o= ViewState["pageMode"];
return(o==null)? PageMode.UploadForm:(PageMode) o;
}
set
{
ViewState["pageMode"]= value;
switch(value)
{
case PageMode.UploadForm: panResult.Visible= panInfo.Visible=!(panUpload.Visible= true); break;
case PageMode.Uploading:
// initialize fields
litRefreshJS.Text= String.Format("<script>setTimeout(\"{0}\",{1});</script>", Page.GetPostBackClientEvent(btnRefresh,""), RefreshTime);
panResult.Visible= panUpload.Visible=!(panInfo.Visible= true);
panProgressBar.Width= 0;
break;
case PageMode.Result:
// result information
litRefreshJS.Text="";
Session.Remove("FileUploadThread");
panUpload.Visible= panInfo.Visible=!(panResult.Visible= true);
break;
}
}
}
// how many bytes has been uploaded.
public long BytesRead
{
get{ object o= ViewState["BytesRead"]; return(o==null)? 0:(long)o;}
set{ ViewState["BytesRead"]= value;}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
if(Session["FileUploadThread"]!= null)
{
// this users has the session, possible there's an unfinished file upload
lblResult.Text="文件正在上载过程中……";
litRefreshJS.Text="";
pageMode= PageMode.Result;
}
else pageMode= PageMode.UploadForm;
}
}
private void btnUpload_Click(object sender, System.EventArgs e)
{
if(theFile.PostedFile.ContentLength==0) return;
lblFilename.Text= Path.GetFileName(theFile.PostedFile.FileName);
lblProgress.Text= String.Format("{0} of{1} bytes(0%)", 0, theFile.PostedFile.InputStream.Length);
string dir= MapPath("files/");
if(!Directory.Exists(dir)) Directory.CreateDirectory(dir);
Session["FileUploadThread"]= new FileUploadThread(dir+ lblFilename.Text, theFile.PostedFile.InputStream);
pageMode= PageMode.Uploading;
}
private void btnRefresh_Click(object sender, System.EventArgs e)
{
FileUploadThread fut=(FileUploadThread) Session["FileUploadThread"];
if(!fut.Uploaded)
{
litRefreshJS.Text= String.Format("<script>setTimeout(\"{0}\",{1});</script>", Page.GetPostBackClientEvent(btnRefresh,""), RefreshTime);
lblProgress.Text= String.Format("{0} of{1} bytes({2}%)", fut.BytesRead, fut.Length, fut.Percent);
panProgressBar.Width= 3* fut.Percent;
}
else
{
if(fut.Exception== null)
lblResult.Text= String.Format("\"<a href='files/{0}'>{0}</a>\"文件上载成功!<br>文件是{1}<br><br>{2}", lblFilename.Text,(chbImportant.Checked)?"重要的":"不重要的", edInfo.Text);
else
lblResult.Text= String.Format("上载文件错误,错误信息如下:{0}<br>{1}", fut.Exception.GetType(), fut.Exception.Message);
pageMode= PageMode.Result;
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
FileUploadThread fut=(FileUploadThread) Session["FileUploadThread"];
if(fut!= null) fut.Cancel();
lblResult.Text="上载文件已经被取消!";
pageMode= PageMode.Result;
}
}
JSP 上传文件进度条怎么做
HTTP本身无法实现上传
进度条
,因为无法使用JS访问文件系统,并对
文件流
进行分块。
可以考虑2种方式实现上传进度条:
1.flash:flash可以访问文件系统,并以二进制方式上传文件,这可以将文件进行分块;
2.使用
ActiveX控件
:这个比较复杂一点,能够监控到每一个字节的进度,可以自己开发或使用第三方库。一般来说,对于前台类型的页面,出于安全和可用性不建议使用ActiveX控件,
进度条拉满是什么意思
拉满指的是将技能,数据等因素或操作直接放到最大的意思。
常见于电竞圈,例如这波操作直接拉满了,效果拉满或者细节拉满。在其他领域也逐渐通用开来。
电竞圈有许多有趣的梗,比如病友,交流病情的梗。病友起源干前职,选手以及斗鱼主播电棍的梗,因为很多玩家游戏段位只有白银:相当干考试20-40分的人,而电棍的段位是钻1,相当干考试90分的人,白银玩家喜欢在直播的时候无限放大电棍的失误,哪怕是因为队友玩的再菜也帮他队友甩锅说是主播问题,再一次忍无可忍的情况下,电棍将白银玩家说的话比喻一个癌症晚期患者说的话;
于是白银玩家就成了病友,白银分段的游戏叫病友局,白银分段的团战对拼被戏称为:交流病情。
好了,文章到这里就结束啦,如果本次分享的js进度条和html5进度条怎么写问题对您有所帮助,还望关注下本站哦!