javascript 進(jìn)度條 實(shí)現(xiàn)代碼
更新時(shí)間:2009年07月30日 18:12:55 作者:
這個(gè)例子是通過測試的。是真真正正根據(jù)記錄的條數(shù)掛鉤的。
首先:建立兩個(gè)類,一個(gè)是用來與資料進(jìn)行連接(數(shù)據(jù)層),另一個(gè)是用來關(guān)聯(lián)前一個(gè)類與頁面的(邏輯層)
新建一個(gè)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 = "數(shù)據(jù)讀取第" + pgbValue+"條,請稍候";
}
if ( pgbValue == pvalues )
{
window.status = "數(shù)據(jù)讀取已經(jīng)完成";
proBar.style.display="none";
Table1.style.display="none";
}
}
建立一個(gè) 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);
}
建立一個(gè) 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>
建立一個(gè) Default.aspx 文件
前臺(tái)代碼如下:
<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>
后臺(tái)代碼如下:
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數(shù)據(jù)
thread.Join();
}
}
#endregion fixedHeader
#region Getgridview
protected DataSet Getgridview()
{
ds = ts.QueryProcS("2009/07", "XXXX");//這個(gè)是邏輯層中的一個(gè)方法
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
}
啟動(dòng)加載頁面時(shí)如下圖所示。

加載完后會(huì)自動(dòng)顯示你要顯示的數(shù)據(jù)。
新建一個(gè)JScsrip.js 文件
代碼如下:
復(fù)制代碼 代碼如下:
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 = "數(shù)據(jù)讀取第" + pgbValue+"條,請稍候";
}
if ( pgbValue == pvalues )
{
window.status = "數(shù)據(jù)讀取已經(jīng)完成";
proBar.style.display="none";
Table1.style.display="none";
}
}
建立一個(gè) common.css
代碼如下:
復(fù)制代碼 代碼如下:
.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);
}
建立一個(gè) progressbar.htm
代碼如下:
復(fù)制代碼 代碼如下:
<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>
建立一個(gè) Default.aspx 文件
前臺(tái)代碼如下:
復(fù)制代碼 代碼如下:
<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>
后臺(tái)代碼如下:
復(fù)制代碼 代碼如下:
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數(shù)據(jù)
thread.Join();
}
}
#endregion fixedHeader
#region Getgridview
protected DataSet Getgridview()
{
ds = ts.QueryProcS("2009/07", "XXXX");//這個(gè)是邏輯層中的一個(gè)方法
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
}
啟動(dòng)加載頁面時(shí)如下圖所示。
加載完后會(huì)自動(dòng)顯示你要顯示的數(shù)據(jù)。
相關(guān)文章
JavaScript實(shí)現(xiàn)動(dòng)態(tài)生成表格
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)生成表格,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08JavaScript如何動(dòng)態(tài)監(jiān)聽DOM元素高度詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript如何動(dòng)態(tài)監(jiān)聽DOM元素高度,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-07-07JavaScript簡單實(shí)現(xiàn)彈出拖拽窗口(二)
這篇文章再次為大家詳細(xì)介紹了JavaScript簡單實(shí)現(xiàn)彈出拖拽窗口的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06Openlayers實(shí)現(xiàn)根據(jù)半徑繪制圓形
這篇文章主要介紹了利用Openlayers實(shí)現(xiàn)繪制三個(gè)圓形,繪制完成之后,三個(gè)圓心連接起來,然后標(biāo)記出每兩個(gè)圓心之間的距離,感興趣的可以了解一下2022-08-08JavaScript指定字段排序方法sortFun函數(shù)
這篇文章主要介紹了JavaScript指定字段排序方法sortFun函數(shù),數(shù)組的排序方法是sort,但是它并不支持根據(jù)指定的字段進(jìn)行排序,而sortFun可以根據(jù)指定的字段進(jìn)行排序,需要的朋友可以參考下2023-05-05JS動(dòng)態(tài)加載當(dāng)前時(shí)間的方法
這篇文章主要介紹了JS動(dòng)態(tài)加載當(dāng)前時(shí)間的方法,涉及html的onload方法及javascript操作時(shí)間的技巧,需要的朋友可以參考下2015-02-02