javascript - 如何使用javascript单击任何按钮时设置标签焦点

标签 javascript asp.net

我的 aspx 页面中有一个 asp:Textbox 和一个 asp:label 控件。我想在使用 javascript 单击按钮时为标签设置焦点。谁能告诉我该怎么做?

非常感谢...

最佳答案

您需要通过 id 或类调用 focus() 来访问该元素:

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

正如 Pointy指出的:当您的意思是通过单击标签来选择文本框时,您只需设置 for将标签上的属性设置为文本框的 ID。

<label for="myTextBox">Label Text</label>

关于javascript - 如何使用javascript单击任何按钮时设置标签焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316119/

相关文章:

javascript - 如何将多维数组映射到 html Canvas 中的矩形网格?

javascript - 单击按钮仅在同一行中显示另一个按钮

javascript - 我遇到错误 Uncaught TypeError : Cannot read property 'toLowerCase' of undefined

c# - 如何使用带进度条的 ASP.NET MVC4 Web Api 上传大文件

c# - 如何使用 EF6 更新多对多表

c# - 使用正则表达式验证英国邮政编码

javascript - style.styleSheet.cssText 在 IE 9 上不起作用

javascript - next() 不通知 subscribe()

javascript - jQuery 验证插件 - 焦点事件与键/鼠标事件不一致

html - 为什么 Visual Studio 警告未终止的字符串常量