Created
October 22, 2013 11:33
-
-
Save rodolfo42/7099070 to your computer and use it in GitHub Desktop.
suporte a onEnter e onShiftEnter para inputs
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.onEnter = function(callback, selector, data, onlyIfShiftKeyPressed){ | |
if($.isFunction(callback)) { | |
$(this).on('keydown.onEnter', selector, data, function(e) { | |
if(e.which != 13) return true; | |
if(onlyIfShiftKeyPressed && !e.shiftKey) return true; | |
e.preventDefault(); | |
callback.apply(this, [e]); | |
}); | |
} | |
return this; | |
}; | |
$.fn.onShiftEnter = function(callback, selector, data){ | |
$(this).onEnter(callback, selector, data, true); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo em http://jsfiddle.net/rodolfo42/5LyMj/