📅  最后修改于: 2023-12-03 15:16:07.191000             🧑  作者: Mango
textarea.append
is a JavaScript method that allows you to append new content to a textarea element dynamically. This method is commonly used to create a textarea input with pre-populated content or to add text to an existing textarea.
The syntax for using textarea.append
is as follows:
textarea.append(content);
textarea
is the reference to the textarea element.content
is the text or HTML content that you want to append to the textarea.const textarea = document.createElement('textarea');
const content = 'This is some pre-populated content.';
textarea.append(content);
In this example, we create a new textarea element using the document.createElement
method. We then use the append
method to add the content
to the textarea, making the textarea display the pre-populated text.
const textarea = document.getElementById('myTextarea');
const additionalContent = 'This is some additional content.';
textarea.append(additionalContent);
In this example, we first find the textarea element with the id myTextarea
using the getElementById
method. We then use the append
method to add additionalContent
to the existing content of the textarea, making it display both the existing content and the additional text.
append
method appends the content at the end of the existing content of the textarea.textarea.append
method is not supported in older versions of Internet Explorer.