Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
121 views
in Technique[技术] by (71.8m points)

javascript - How to get the content of a text area into a js file

I am aware that tis question has been asked before however I am shit at html so I couldn't really apply the answer to my case.

Basically, I would like to get the content of what is written in the textarea in real time so it updates in realtime onto a javascript file. main.html

<textarea type="text" name="keywords" cols="100" rows="100"></textarea> <br />

Thanks in advance!

question from:https://stackoverflow.com/questions/65920902/how-to-get-the-content-of-a-text-area-into-a-js-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try a framework, for example React, Angular, Vue. Whatever fits you best.

Or:

const textarea = document.getElementById('myTextarea')
const currentValue = ''

function update(e) {
   currentValue = textarea.value
}

textarea.addEventListener('keydown', update)
textarea.addEventListener('keyup', update)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...