javascript 進度條 實現代碼

來源:互聯網
上載者:User

首先:建立兩個類,一個是用來與資料進行串連(資料層),另一個是用來關聯前一個類與頁面的(邏輯層)
建立一個JScsrip.js 檔案
代碼如下: 複製代碼 代碼如下:function setPgb(pgbID, pgbValue,pvalues)
{
if ( pgbValue <= pvalues )
{
if (lblObj = document.getElementById(pgbID+'_label'))
{
lblObj.innerHTML =Math.ceil((pgbValue/pvalues)*100) + '%'; // change the label value
}
if ( pgbObj = document.getElementById(pgbID) )
{
var divChild = pgbObj.children[0];
pgbObj.children[0].style.width = Math.ceil((pgbValue/pvalues)*240);//pgbValue;
}
window.status = "資料讀取第" + pgbValue+"條,請稍候";
}
if ( pgbValue == pvalues )
{
window.status = "資料讀取已經完成";
proBar.style.display="none";
Table1.style.display="none";
}
}

建立一個 common.css
代碼如下: 複製代碼 代碼如下:.bi-loading-status
{
/**//*position: absolute;*/
width: 250px;
padding: 1px;
overflow: hidden;
}
.bi-loading-status .text{
white-space: nowrap;
overflow: hidden;
width: 100%;
text-overflow: ellipsis;
padding: 1px;
}
.bi-loading-status .progress-bar {
border: 1px solid ThreeDShadow;
background: window;
height: 10px;
width: 100%;
padding: 1px;
overflow: hidden;
}
.bi-loading-status .progress-bar div {
background: Highlight;
overflow: hidden;
height: 100%;
filter: Alpha(Opacity=0, FinishOpacity=100, Style=1, StartX=0, StartY=0, FinishX=100, FinishY=0);
}

建立一個 progressbar.htm
代碼如下: 複製代碼 代碼如下:<body topmargin="0" leftmargin="0">
<table width="100%" height="100%" ID="Table1" runat=server>
<tr>
<td align="center" valign="middle">
<DIV class="bi-loading-status" id="proBar" style=" LEFT: 425px; TOP: 278px" align="left">
<DIV class="text" id="pgbMain_label" align="left"></DIV>
<DIV class="progress-bar" id="pgbMain" align="left">
<DIV STYLE="WIDTH:5%"></DIV>
</DIV>
</DIV>
</td>
</tr>
</table>
</body>

建立一個 Default.aspx 檔案
前台代碼如下: 複製代碼 代碼如下:<head>
<script language="javascript" src="JScript.js" type="text/javascript"></script>
</head>
<body >
<form id="Form1" method="post" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
</body>

後台代碼如下: 複製代碼 代碼如下:public partial class _Default : System.Web.UI.Page
{
DataSet ds;
text ts = new text();
int count = 0;
#region Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
ds = Getgridview();
count = ds.Tables[0].Rows.Count;
Response.Write("count=" + count);
string strFileName = Server.MapPath("progressbar.htm");
StreamReader sr = new StreamReader(strFileName, System.Text.Encoding.Default);
string strHtml = sr.ReadToEnd();
Response.Write("<div style='align:center;valign:bottom;'>" + strHtml + "</div>");
sr.Close();
Response.Flush();
Thread thread = new Thread(new ThreadStart(ThreadProc));
thread.Start();
LoadData(ds);
// Getgridview();
//load資料
thread.Join();
}
}
#endregion fixedHeader
#region Getgridview
protected DataSet Getgridview()
{
ds = ts.QueryProcS("2009/07", "XXXX");//這個是邏輯層中的一個方法
return ds;
}
#endregion
#region ThreadProc
private void ThreadProc()
{
string strScript = "<script>setPgb('pgbMain','{0}','" + count + "');</script>";
for (int i = 0; i <= count; i++)
{
System.Threading.Thread.Sleep(80);
Response.Write(string.Format(strScript, i));
Response.Flush();
}
}
#endregion LoadData
#region LoadData
private void LoadData(DataSet dds)
{
for (int m = 0; m < count; m++)
{
for (int i = 0; i < dds.Tables[0].Columns.Count; i++)
{
}
}
this.GridView1.DataSource = dds.Tables[0].DefaultView;
this.GridView1.DataBind();
}
#endregion Web Form Designer generated code
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**/
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}

啟動載入頁面時如所示。

載入完後會自動顯示你要顯示的資料。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.