开发者

Execute function by pressing "return" using jQuery?

i have two text inputs like the following, i don't want to use <form> , so i want when people press "return" BUTTON after filling the inputs, a function called "doit()" should be executed.

<script>
function doit(){
alert("you submitted the info");
..........ajax code........
}
</script>

<input type="text" id="email" />
<input type="text" id开发者_如何学Python="skills" />

Thanks


The following will do what you are looking for.

$('#emails, #skills').keypress(function(e){
   if( e.keyCode == $.keyCode.ENTER || e.keyCode == $.keyCode.NUMPAD_ENTER ){
     yourSubroutine();
   }
});


$('#name, #last').bind('keydown', function(e) {
                    if (e.keyCode == 13 || e.keyCode == 108) {
                        doit();
                    }
                });

KeyCode can be found here


Check out this question. Essentially, you'll want to bind a keypress listener, and then check for the return key.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜