timer 焦点

function txtFocus()
        {
            var exp=new Date();
            exp.setTime(exp.getTime() + 60*60*1000);
            document.cookie = "focusTextBox="+ event.srcElement.id + ";expires=" + exp.toGMTString();
        }


           <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnInit="UpdatePanel1_Init">
                <ContentTemplate>
                <asp:TextBox runat=server ID=zwei Columns="10" Rows="10" TextMode="MultiLine"></asp:TextBox>
                    <asp:Timer ID="Timer1" runat="server" Interval="5000">
                    </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel>
       
       
        </div>

protected void Page_Load(object sender, EventArgs e)
    {
        this.zwei.Attributes.Add("onfocus","txtFocus()");
    }
    protected void UpdatePanel1_Init(object sender, EventArgs e)
    {
        if (this.Request.Cookies["focusTextBox"] != null)
        {
            string s = this.Request.Cookies["focusTextBox"].Value;//读出post之前光标停留在哪个TextBox之中
            string script =
            "var inp = $get('" + s + "');" +
            "window.setTimeout('var r = inp.createTextRange();r.collapse(false);r.select();', 10);";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.Page.GetType(), "ScriptBlock", script, true);
        }

    }

原文地址:https://www.cnblogs.com/zwei1121/p/1238791.html