本文介绍了如何触发输入按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在输入上触发输入键。也就是说,在响应某些其他事件(不是按键)时,我需要触发值为13的按键。
I need to know how to trigger an enter key on an input. That is, in response to some other event (not a keypress), I need to trigger a keypress of value 13.
(澄清,我不想触发一些当按下回车键时的事件。如果我不知道怎么做,我会发现在SO上已经多次询问和回答。我想要反过来。我正在尝试开发一种需要我模仿的解决方法'输入'按键。)
(Clarification, I do not want to trigger some event when the enter key is pressed. If I didn't know how to do that, I could find that that's been asked and answered several times on SO. I want the reverse. I am trying to develop a workaround that requires I emulate an 'enter' keypress.)
推荐答案
你可以这样做 -
var e = $.Event( "keypress", { which: 13 } );
$('#yourInput').trigger(e);
- http://api.jquery.com/category/events/event-object/
- http://api.jquery.com/trigger/
这篇关于如何触发输入按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!