开发者

How to press a button with Enter Key

开发者 https://www.devze.com 2023-03-02 03:11 出处:网络
How to bind click(f开发者_运维问答rom Button1\'s click event) eventin textbox When I pressed the enter key $(\'#idoftextbox\').keypress(function (e) {

How to bind click(f开发者_运维问答rom Button1's click event) event in textbox When I pressed the enter key


$('#idoftextbox').keypress(function (e) {
    var code = e.keyCode || e.which;
    if (code === 13) {
        //enter has been pressed
    };
});


<input type="text" name="textbox" id="textbox" />

$("#textbox").bind('keypress', function(e)
{
   if(e.which == 13) 
   {
       // enter key was hit, do what you need to do here
   }
});

Since you didn't say what "textbox" means to you (as it can be textarea too), I assumed some dummy markup that I posted and then I bound the event to it. I don't see the reason for binding an event to click and then bind event after that to the element.

0

精彩评论

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