Created
October 11, 2013 00:52
-
-
Save thirdj/6928024 to your computer and use it in GitHub Desktop.
enter plugin
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
$.fn.enter = function(handler) { | |
return this.live("keypress", function(e) { | |
if (e.which == 13) { | |
e.preventDefault(); | |
if (handler) { | |
$(this).bind("enter", handler); | |
$(this).trigger("enter"); | |
$(this).unbind("enter"); | |
} | |
} | |
}); | |
}; | |
/* | |
use | |
$('input').enter('handler'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment