JQuery Event for user pressing enter in a textbox?
问题 Is there any event in Jquery that's triggered only if the user hits the enter button in a textbox? Or any plugin that can be added to include this? If not, how would I write a quick plugin that would do this? 回答1: You can wire up your own custom event $('textarea').bind("enterKey",function(e){ //do stuff here }); $('textarea').keyup(function(e){ if(e.keyCode == 13) { $(this).trigger("enterKey"); } }); http://jsfiddle.net/x7HVQ/ 回答2: $('#textbox').on('keypress', function (e) { if(e.which ===