Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从TextArea中删除文本,并使用javascript将新数据插入其中_Javascript_Html - Fatal编程技术网

从TextArea中删除文本,并使用javascript将新数据插入其中

从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

在这个程序中,当我输入textarea时,它应该删除textarea值,然后将其值更新为“hello world”,但它不起作用。如果我键入c键,那么它应该显示“Hello world”,但它显示的是带有我键入的c键的“Hello worldc”

const textArea=document.querySelector('.textArea');
textArea.addEventListener('keydown',函数(){
textArea.value='';
textArea.value='Hello world';
});

使用KeyUp事件

是的,它可以工作!谢谢
textArea.addEventListener('keyup', function () {