Auto arrow (right) key press event?

本小妞迷上赌 提交于 2020-01-14 06:57:37

问题


Is it possible to create an auto key press event? I want to flip a book once automatically after refreshing the site?

Thanks in advance!


回答1:


This will do it:

$(document).ready(function() {
    var e = $.Event('keydown', { keyCode: 39 });// right arrow key
    $(document).trigger(e);
});

References:

  • JS trigger keydown event
  • Is it possible to simulate key press events programmatically?
  • Trigger a keypress/keydown/keyup event in JS/jQuery?



回答2:


This solved the problem:

$(window).load(function()  {
    var e = $.Event('keydown', { keyCode: 39 });// right arrow key
    setTimeout(function() {
    $(document).trigger(e);
             }, 1000);
});

Many thanks!



来源:https://stackoverflow.com/questions/35370794/auto-arrow-right-key-press-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!