将焦点设置为文本框旁边的按钮 [英] Setting focus to a button next to a text box
问题描述
我有一个和这个非常相似的问题:将焦点从文本框设置为按钮?
在我的页面上,有一个文本框,旁边有一个按钮。这是一个ASP.NET页面,但按钮只是一个标准的输入标签,点击后,就有一个客户端函数调用。
我希望它当你按下回车键,该按钮被点击。我设法最初使用 $(#mybutton)。focus()
来设置焦点,但是当您点击文本框时,按钮会失去焦点。有没有什么办法可以达到我想要的?
我不太清楚这是不是你要问的问题,但是这会在回车键上看到一个按键,当它发生的时候点击按钮。
$('#mybutton')。 click();
event.preventDefault();
}
});
I have a question that is very similar to this one: Setting focus to a button from from text box?
On my page, there is a text box, with a button next to it. It is an ASP.NET page, but the button is just a standard input tag, and when clicked, there is a client side function called.
I want it so that when you hit enter, that button is clicked. I have managed to set focus initially using $("#mybutton").focus()
, but when you click into the text box, the button loses the focus.
Is there any way to achieve what I want here?
I'm not quite sure if this is what you're asking, but this will watch for a keypress on the enter key and click the button when it happens.
$('#theinput').keypress(function(event) {
if (event.keyCode == '13') {
$('#mybutton').click();
event.preventDefault();
}
});
这篇关于将焦点设置为文本框旁边的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!