How do you simulate typing using jQuery?

后端 未结 3 737
独厮守ぢ
独厮守ぢ 2021-01-05 04:18

Like how the click() can be used to trigger a click event on an element, is there any way to simulate the typing of a string?

3条回答
  •  伪装坚强ぢ
    2021-01-05 04:34

    If you really want to simulate typing (i.e. including triggering the events and appending the text to an input or textarea element), you can use the jQuery simulate extended plugin:
    http://j-ulrich.github.com/jquery-simulate-ext

    Then you can use

    $('input').simulate("key-sequence", {sequence: "This is a test", delay: 10});
    

    to simulate the typing of the text "This is a test" with a 10ms delay between each key press.

    Disclaimer: I'm the author of the plugin.

提交回复
热议问题