jQuery has a .keypress
method accepting no arguments that simulates a keypress.
$("#target").keypress();
Will trigger a keypress on #target
If you'd like to also select which key was pressed, you can use .trigger
. This example is from the docs:
var e = $.Event("keydown", { keyCode: 8}); //"keydown" if that's what you're doing
$("body").trigger(e);
The key code 8 is the key code for backspace in JavaScript.
Let me know how that works for you :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…