简体   繁体   中英

How to set focus on user control textbox in aspx page?

如何通过在aspx页面中使用jquery / JavaScript函数将焦点设置在asp:TextBox中,该文件放在用户控件中?

You can use id selector and use focus() method. For using jQuery you need to include jQuery and ensure your element is available in DOM before you access it. You can use document.ready for that.

$('#txt1').focus();

Or using plain JavaScript, focus()

document.getElementById('txt1').focus();

If you do not have ClientIDMode = static then you will need to use ClientID

$('#<%= txt1.Client %>').focus();

你可以试试jQuery:

$('#txt').focus();
function myfocus2() {
 $('#<%=TextBox2.ClientID %>').focus();
}

There should be no space between = and TextBox2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM