[英]How to fire keyboard event to enter text in textarea javascript
我對創建自動腳本感興趣,該腳本輸入的狀態在提交前會顯示在文本框中。 我希望我可以使用鍵盤事件進入文本框,因為我認為有一些自動檢測程序可以實現鍵盤事件檢查,因此簡單的textarea.value = "something"
將不起作用。
這是我的代碼:
<html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> </head> <body> <textarea id="reply_message"></textarea> <script> window.onload = function() { $('#reply_message').focus(); var e = $.Event('keydown', { keyCode: 65 }); $('#reply_message').trigger(e); } </script> </body> </html>
我希望在其上輸入字母“ a”,但它根本無法正常工作,有人可以告訴我該怎么做嗎? 謝謝
也許嘗試這樣的事情:
function onTestChange() { var key = window.event.keyCode; // If the user has pressed enter if (key === 13) { document.getElementById("txtArea").value = document.getElementById("txtArea").value + "\\n*"; return false; } else { return true; } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.