开发者

Setting focus to a button next to a text box

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();
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜