用javascript实现(页面正在加载的效果)

2016-02-19 22:13 9 1 收藏

get新技能是需要付出行动的,即使看得再多也还是要动手试一试。今天图老师小编跟大家分享的是用javascript实现(页面正在加载的效果),一起来学习了解下吧!

【 tulaoshi.com - Web开发 】

代码文件:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
namespace AjaxTest
{
    /**//// summary
    /// WebForm2 的摘要说明。
    /// /summary
    public class WebForm2 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Label Label1;
   
        private void Page_Load(object sender, System.EventArgs e)
        {
            Response.Write("div id='mydiv' ");
            Response.Write("_");
            Response.Write("/div");
            Response.Write("scriptmydiv.innerText = '';/script");
            Response.Write("script language=javascript;");
            Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
            Response.Write("{var output; output = '正在装载页面';dots++;if(dots=dotmax)dots=1;");
            Response.Write("for(var x = 0;x dots;x++){output += '·';}mydiv.innerText =  output;}");
            Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
            Response.Write("window.setInterval('ShowWait()',1000);}");
            Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
            Response.Write("window.clearInterval();}");
            Response.Write("StartShowWait();/script");
            Response.Flush();//这一句是最关键的
        }

        private void Button1_Click(object sender, System.EventArgs e)
        {
            //当点击按钮时,假设请求需要较长时间(这里设置为10秒)
            System.Threading.Thread.Sleep(10000);
            this.Label1.Text = "终于加载完成啦";
        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
       
        /**//// summary
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// /summary
        private void InitializeComponent()
        {   
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

    }
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

页面文件:
%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="AjaxTest.WebForm2" %
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
HTML
    HEAD
        titleWebForm2/title
        meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"
        meta name="CODE_LANGUAGE" Content="C#"
        meta name="vs_defaultClientScript" content="JavaScript"
        meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"
        script
         HideWait();
        /script
    /HEAD
    body MS_POSITIONING="GridLayout"
        form id="Form1" method="post" runat="server"
            FONT face="宋体"
                asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 480px; POSITION: absolute; TOP: 200px" runat="server"
                    Text="Button"/asp:Button
                asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 632px; POSITION: absolute; TOP: 240px" runat="server"Label/asp:Label/FONT
        /form
    /body
/HTML

来源:https://www.tulaoshi.com/n/20160219/1627959.html

延伸阅读
标签: Web开发
style type="text/css"    #oContainer {          width: 600px;          height: 500px;          border: 1px solid menu;   ...
标签: Web开发
在网页源代码中加入下面的代码,则该窗口将在20秒钟之后自动关闭!这与跳出式小窗口配合使用是再好不过啦!代码中“i=20”表示关闭的延迟时间为20秒,可任意修改。 以下是引用片段: script language="javascript" !-- function clock(){i=i-1 document.title="本窗口将在"+i+"秒后自动关闭!"; if(i0)setTimeout("clock();",1000); else...
标签: Web开发
function getparastr(strname)   {    var hrefstr,pos,parastr,para,tempstr;    hrefstr = window.location.href;    pos = hrefstr.indexOf("?")    parastr = hrefstr.substring(pos+1);    para = parastr.split("&");    tempstr="";    for(i=0;ipara....
标签: Web开发
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head meta http-equiv="Content-Type" content="text/html; charset=gb2312" / title仿Flash广告图片...
标签: Web开发
有很多种方法来实现图片的预加载,通常大部分使用Javascript让事情滚动。不要再受Javascript预载的束缚了吧,用CSS你就可以毫不麻烦的预载你的图片。 为什么使用预载 你为什么会考虑使用预载呢?你是否曾有个网站,在那个网站你要滚动你的导航然后有个延迟直到图片被加载完……嘿嘿。预载将在这方面帮助你。它将在页面加载的时候加载那些图片...

经验教程

314

收藏

67
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部