![](/img/trans.png)
[英]JavaScript - How to remove new line from textarea if no text exists before?
[英]Remove text from TextArea and insert new data into it using javascript
在這個程序中,當我輸入 textarea 時,它應該刪除 textarea 值,然后將其值更新為“hello world”,但它不起作用。 如果我鍵入 c 鍵,那么它應該顯示“Hello world”,但它使用我鍵入的 c 鍵顯示“Hello worldc”。
const textArea = document.querySelector('.textarea'); textArea.addEventListener('keydown', function () { textArea.value = ''; textArea.value = 'Hello world'; });
<textarea class="textarea"></textarea>
textArea.addEventListener('keyup', function () {
使用 KeyUp 事件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.