简体   繁体   English

Javascript 从 textarea 获取值并动态填写不同的输入字段

[英]Javascript fetch value from textarea and fill in different input field dynaically

I want to fetch value from a textarea dynamically while I write and fill the value in a different input field.我想在写入时动态地从文本区域中获取值并将值填充到不同的输入字段中。 So that the input autofill itself from the text I write in textarea.这样输入会自动填充我在 textarea 中编写的文本。

Suppose the textarea id is 'myTextArea', and the input id is 'myInput'.假设textarea id 是“myTextArea”, input id 是“myInput”。 Using an Event Listener and the onKeyUp event (or whichever event suits your needs), you could simply do:使用事件侦听器onKeyUp 事件(或任何适合您需要的事件),您可以简单地执行以下操作:

const myTextArea = document.getElementyById('myTextArea');
const myInput = document.getElementyById('myInput');
myTextArea.addEventListener('keyup', () => myInput.value = myTextArea.value);

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

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