加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用 AJAX 实现 打字效果 、、 、

发布时间:2020-12-15 21:05:40 所属栏目:百科 来源:网络整理
导读:新建Default9.aspx 页面 使用 SriptManager 和 UpdataPanel在 UpdataPanel 放一个 、timer实现 、使用两个 Viewstate,ViewState[“index”]存储下标和ViewState[“content”]打印的内容、、、 代码 : using System; using System.Collections.Generic; usin

新建Default9.aspx 页面

使用 SriptManager 和 UpdataPanel在 UpdataPanel 放一个 、timer实现 、使用两个 Viewstate,ViewState[“index”]存储下标和ViewState[“content”]打印的内容、、、



代码 :



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

public partial class Default6 : System.Web.UI.Page
{


public int index {
get { return (int)ViewState["index"]; }
set { ViewState["index"] = value; }
}
public String content
{
get { return (String)ViewState["content"]; }
set { ViewState["content"] = value; }
}

protected void Page_Load(object sender,EventArgs e)
{
if (!IsPostBack)
{
content = " 大家好 ,ajax test、、、、";
index = 0;
Timer1.Enabled = true;
}

}

protected void Timer1_Tick(object sender,EventArgs e)
{


this.Label1.Text+=content[index].ToString();
index++;
if (index >=content.Length) {

Timer1.Enabled = false;
}
}



}

页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default9.aspx.cs" Inherits="Default9" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"> </asp:Timer> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读