jquery - How can I trigger a keyup event and pass the key? -
i have field "corrects" type. have code written prevents functionality when arrow keys pressed:
handlekeyup: function(e) { var arrowkeys = _.range(37, 41), key = e.which; // allow user move cursor keyboard if ($.inarray(key, arrowkeys) < 0) { this.removeinvalidcharacters(); } },
we write unit test this; however, can't figure out how pass e.which
via $input.trigger('keyup')
. know second parameter of trigger allows send "extra options"; however, passes values more values handlekeyup
function. ideas?
try -
var e = $.event("keyup"); e.which = 37; $input.trigger(e);
http://api.jquery.com/category/events/event-object/
as of jquery 1.6, can pass object jquery.event() , properties set on newly created event object.
// create new jquery.event object specified event properties. var e = jquery.event("keydown", { keycode: 64 }); // trigger artificial keydown event keycode 64 jquery("body").trigger( e );
Comments
Post a Comment