如何在页面加载后将光标聚焦在文本框上。 [英] How to focus cursor on textbox after page load.

查看:63
本文介绍了如何在页面加载后将光标聚焦在文本框上。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个文本框,其中前3个文本框取整数值,第4个文本框显示添加结果。我将所有textbox的autopost back属性设置为true,因为我需要在文本更改为任何文本框时立即添加。问题是当我键入一个文本框并尝试切换另一个文本框时,光标焦点从第二个文本框中丢失。请有人帮助在回发后将光标放在下一个文本框上。这是我的代码。

 <   asp:ScriptManager     ID   = < span class =code-keyword> ScriptManager1    runat   =  server >  <   / asp:ScriptManager  >  
< asp:UpdatePanel ID = UpdatePanel1 runat = server >
< ContentTemplate >
< asp:TextBox ID = TextBox1 runat = server > < / asp:TextBox >
< asp:TextBox ID = TextBox2 runat = 服务器 > < span class =code-keyword>< / asp:TextBox >
< asp:TextBox ID = TextBox3 runat = 服务器 > < / asp:TextBox >
<
asp:TextBox ID = TextBox4 runat = server > < / asp:TextBox >
< / ContentTemplate >
< / asp:UpdatePanel >

解决方案

当网页加载时写下代码:

  .textbox1.Focus(); 


你可以通过多种方式实现:



我使用HTML5你需要做的就是使用自动对焦属性。



如果您使用在页面加载时调用的任何JS,您可以使用jquery显式指定它

 


' #textboxID')。 focus();





或者您可以在页面加载中使用服务器文本框控件属性;

< pre lang =c#> this .textboxName.focus();


I have 4 textbox where first 3 textbox take integer value and 4th textbox show there addition result. I make all textbox's autopost back property true because I need to add immediately when text change into any textbox. Problem is when I type one textbox and try to switch another then the cursor focus lost from the 2nd textbox. Please someone help to get cursor on the next textbox after postback. Here I my code.

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    </ContentTemplate>
</asp:UpdatePanel>

解决方案

when webpage load write below code :

this.textbox1.Focus();


You can do it in a variety of ways:

I you are using HTML5 all you need to do is use the autofocus property.

If you are using any JS thats being called on page load you can explicitly specify it using jquery


('#textboxID').focus();



or you can use the server textbox control property in the page load;

this.textboxName.focus();


这篇关于如何在页面加载后将光标聚焦在文本框上。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆