admin管理员组文章数量:1318155
I want to manually invoke enter key press event on textbox through JS or jQuery.
I don't want to capture that event. I just want to invoke enter key press event.
I want to manually invoke enter key press event on textbox through JS or jQuery.
I don't want to capture that event. I just want to invoke enter key press event.
Share Improve this question edited Nov 28, 2022 at 19:11 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 22, 2011 at 18:52 Aditya KAditya K 1591 gold badge4 silver badges13 bronze badges 2- 3 Do you want to submit a form? – David Hedlund Commented Dec 22, 2011 at 18:54
- What do you want to achieve? Should that event trigger the existing key handler bound to the textbox? – Šime Vidas Commented Dec 22, 2011 at 18:56
3 Answers
Reset to default 8You can trigger it like:
// dummy event listener
$("input").keydown(function() { return true; });
var keyEvent = jQuery.Event("keydown");
keyEvent.keyCode = 13;
$("input").trigger(keyEvent);
See this post too: Definitive way to trigger keypress events with jQuery
Trigger the event with jQuery:
$(document).trigger('keypress');
You are looking for synthetic events. It's quite plicated. The following library takes care of it for you... http://jupiterjs./news/syn-a-standalone-synthetic-event-library
Here's example code using their lib
Syn.click( {},'hello' )
.type( 'Hello World' )
.delay() //waits 600ms seconds by default
.drag( $('#trash') , function() {
ok( $('#hello').length == 0, "removed hello" )
});
本文标签: javascriptIs there any way to manually invoke quotEnter keyquot event on a textboxStack Overflow
版权声明:本文标题:javascript - Is there any way to manually invoke "Enter key" event on a textbox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742042680a2417620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论