[英]how to set focus for label when click the any button using javascript
I have one asp:Textbox and one asp:label control in my aspx page. 我的aspx页面中有一个asp:Textbox和一个asp:label控件。 I want to set focus for label when clicking the button using javascript.
我想在使用javascript单击按钮时为标签设置焦点。 Can anyone tell me how to do this?
谁能告诉我该怎么做?
Many thanks... 非常感谢...
You need to access the element via an id or a class an call focus() : 您需要通过一个ID或一个调用focus()的类来访问该元素:
document.getElementById('myTextBox').focus();
As Pointy pointed out: When you mean by clicking on a label to select the textbox, you just need to set the for attribute on the label to the ID of the textbox. 正如Pointy 指出的那样:当您通过单击标签以选择文本框时,只需将标签上的for属性设置为文本框的ID。
<label for="myTextBox">Label Text</label>
use `.focus()` it will do the focus part
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.