How to trigger an input event with jQuery? -


I want to add 'a' to the value of input when I click on a button

This is my Code is (with jQuery 1.4.4):

  $ ("# button"). Click (function () {$ ("# input"). Trigger ("focus"); var e = JQuery.Event ("keypress"); e.which = '97'; $ ("# input"). Trigger (e);})   

However, this was the only trigger 'focus' event, but 'keypress' failed.

this way ?? Sorry, I'm confused with your articles ..

 Click  $ ("# button") (function () {$ ("# input"). Trigger ("keypress") / / If you need .., then you can trigger such a keypad .val (function (i, val) {return val + 'a';});});   

Reference:

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 -