javascript - Retrieve keypress event -


Implementing keypress to submit when I press Enter. I have created a jquery plugin and some Need help:

  jQuery.fn.enterpress = function (obj, button) {if (e.which == 13) {jQuery (button). Click (); }};   

In this function, I retrieve the obz (html form), and the button (which will be one click).

I'm not sure, but I probably do not need this 'obj'. My problem is that I do not have this 'E'. I tried several ways, but I do not know if I How can i get back

I created it:

  jQuery ('#' + obj.id) .capers (function (e) {}   < P> But the function was removed twice, sometimes three times.  

Thanks

In jQuery, there is a built-in method for this called quote.

  $ (" # target "). Event (event) {if (event.which == 13 } {Event.preventDefault (); // do stuff here}}   

If you want to add more common method for binding, an 'Object' keyboard event has a jQuery object And then clicking on a button (as you have mentioned in your question and comment), you can do something like this:

  var $ button = jQuery ('#somebutton') ; JQuery.fn.enterPress = function (callback) {jQuery (this) .keypress (function) {if (event.which == 13} {event.preventDefault (); callback ();}});}; $ Button (function () (warning ('button was clicked');}) jQuery ('# target'). EnterPress (fu Nction () {// what you want to do after entering $ button Is pressed. Click (); });   



Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -