How to trigger backspace on a textfield?
问题 Say I have this: <textarea id="myarea">Hello</textarea> How would i trigger backspace on that textarea possibly using trigger() and key codes. The code for backspace is 8. And i am not looking for this: $('#myarea').val( $("myarea").val().slice(0,-1) ); I need to simulate someone actually pressing the 'backspace' key on their keyboard. Thanks 回答1: You can create a keydown event: var e = jQuery.Event("keydown", { keyCode: 20 }); Then trigger it in your textarea: $("#myarea").trigger( e );