Skip to content

Instantly share code, notes, and snippets.

@perrywky
Last active September 30, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perrywky/1851844 to your computer and use it in GitHub Desktop.
Save perrywky/1851844 to your computer and use it in GitHub Desktop.
jQuery.enter(fun)
//jQuery扩展,当用户按了回车键后,会触发函数
(function($){
$.fn.enter = function(fun){
if($.isFunction(fun)){
this.keypress(function(e){
if(e.keyCode == 13){
fun.call(this, e);
}
});
}
return this;
};
})(jQuery);
$('#some_input').enter(function(){
alert('user press enter!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment