gpt4 book ai didi

c# - 在页面加载时将焦点设置在文本框上

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:07 25 4
gpt4 key购买 nike

How do you automatically set the focus to a textbox when a web page loads?里面的信息我已经试过了

 <asp:TextBox ID="tbSearchLastName" runat="server" style="float:right" CssClass="search" tabindex="1" meta:resourcekey="tbSearchLastNameResource" />

<script type="text/javascript">
window.onload = function () {
document.getElementById("tbSearchLastName").focus();
};
</script>

我希望页面加载时页面焦点位于文本框上,但出现错误:

“无法获取属性‘focus’的值:对象为 null 或未定义”

谢谢。

最佳答案

你必须这样做......

document.getElementById('<%= tbSearchLastName.ClientID%>').focus();

关于c# - 在页面加载时将焦点设置在文本框上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7349682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com