有沒有辦法將鍵盤事件重播到文本字段并讓接收輸入字段將該字符添加到其文本中?因為我不能讓它工作。假設(shè)我按下a鍵盤,body 上的全局處理程序會捕獲它?,F(xiàn)在我想將它重播到給定的文本字段。因此,如果用戶按下a鍵盤,它將僅基于事件顯示在文本字段內(nèi)。輸入時彈出事件,但沒有輸入字符。這可能嗎?我想避免使用.val();操作輸入文本例子:$('body').on('keyup', eKeyUp);$('#mancineni').on('keyup', eKeyUpINPUT);function eKeyUp(e){ $e = $.Event('keyup'); $e.which = e.which; $e.charCode = e.charCode; $e.keyCode = e.keyCode; $e.shiftKey = e.shiftKey; $e.key = e.key; $('#mancineni').trigger($e); //$('#mancineni').focus();}function eKeyUpINPUT(e){ console.log('g', e) e.stopPropagation();}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><input type="text" id="mancineni">
將全局鍵盤事件傳遞到文本字段
富國滬深
2022-10-13 16:57:42