简体   繁体   English

在不指定元素的情况下模拟Enter键

[英]Simulate Enter press key without specifing the element

I tried sendkeys plugin and others. 我尝试了sendkeys插件和其他。

Is there a way to simulate Enter key pressed without element? 有没有一种方法可以模拟没有元素按下的Enter键?

$("div.myclass").click(); // Put focus on my element - works
$("div.myclass span").sendkeys("Test"); // using sendkeys plugin send the input - works.

setTimeout(function(){
console.log('trigger');
//$("div._1mf").trigger({type: 'keydown', key: 'enter'}); // this one just insert new line...
e = jQuery.Event("keypress")
e.which = 13
    $("div.myclass").keypress(function(){ // this one doesn't work
    }).trigger(e)
},2000);

I have already element focused and input inserted, I need just simulate Enter press key to send the text, how that can be done? 我已经聚焦了元素并插入了输入,我只需要模拟Enter键来发送文本,该怎么办?

我认为您可能想要做的是,提交您的输入所驻留的表单?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM