篡改猴刺激按回车不起作用

TamperMonkey stimulate press enter does not work

本文关键字:回车 不起作用 刺激      更新时间:2023-09-26

我有以下函数:

var e = jQuery.Event("keydown");
e.which = 16; // # Some key code value
$("textarea.my_input").trigger(e);

但是,这不起作用。(选择器是正确的,因为如果我做 focus((,它可以工作(。我想知道我做错了什么吗?这似乎很简单,但我无法让它工作。或者有更好的方法可以做到这一点吗?

执行以下操作:

$(document).ready(function() {
    $(document).on("keydown", function(e) {        
        $("textarea.my_input").focus();        
        $("textarea.my_input").append(String.fromCharCode(e.which));        
    });
});

js小提琴