从TextArea中删除文本,并使用javascript将新数据插入其中
在这个程序中,当我输入textarea时,它应该删除textarea值,然后将其值更新为“hello world”,但它不起作用。如果我键入c键,那么它应该显示“Hello world”,但它显示的是带有我键入的c键的“Hello worldc”从TextArea中删除文本,并使用javascript将新数据插入其中,javascript,html,Javascript,Html,在这个程序中,当我输入textarea时,它应该删除textarea值,然后将其值更新为“hello world”,但它不起作用。如果我键入c键,那么它应该显示“Hello world”,但它显示的是带有我键入的c键的“Hello worldc” const textArea=document.querySelector('.textArea'); textArea.addEventListener('keydown',函数(){ textArea.value=''; textArea.val
const textArea=document.querySelector('.textArea');
textArea.addEventListener('keydown',函数(){
textArea.value='';
textArea.value='Hello world';
});代码>
使用KeyUp事件是的,它可以工作!谢谢
textArea.addEventListener('keyup', function () {