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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…