To clear all text in a text area when a button is clicked, you can use JavaScript to set the value of the text area to an empty string. Here's an example:

<textarea id='myTextarea'></textarea>
<button onclick='clearTextarea()'>Clear Text Area</button>

<script>
  function clearTextarea() {
    document.getElementById('myTextarea').value = '';
  }
</script>

In this example, we have a text area with an ID of 'myTextarea' and a button with an onclick event that calls the 'clearTextarea' function. The function uses the 'getElementById' method to get a reference to the text area element and sets its 'value' property to an empty string, effectively clearing all text from the text area.

Clear Text Area Content with JavaScript Button Click

原文地址: https://www.cveoy.top/t/topic/mDoP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录