AngularJS unit test for keypress event

后端 未结 1 1990
梦谈多话
梦谈多话 2021-01-15 03:04

I set up a directive that binds a function for the keydown and keypress events. The directive sets the focus for an input on a form when a shortcut key is entered.

相关标签:
1条回答
  • 2021-01-15 03:16

    You can use jQuery with AngularJS, and you can do this fairly easily in jQuery with the trigger() API call. You can pass an event into trigger, in this case the event is the

    var aEvent = jQuery.Event("keydown");
    aEvent.which = 40; //this is the ASCII value of the key you want to press
    $("input").trigger(aEvent);
    

    Then repeat for the other characters.

    0 讨论(0)
提交回复
热议问题