Last active
September 30, 2015 19:38
-
-
Save perrywky/1851844 to your computer and use it in GitHub Desktop.
jQuery.enter(fun)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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