可以使用CSS中的resize属性来实现textarea的高度自适应并且不受最大高度限制。具体实现方法如下:

  1. 在CSS中为textarea添加以下样式:

textarea { resize: vertical; min-height: 50px; max-height: none; }

其中,resize: vertical;表示垂直方向可以拉伸,min-height: 50px;表示最小高度为50px,max-height: none;表示没有最大高度限制。

  1. 如果需要textarea的高度能够随着输入内容自动增加,可以使用JavaScript监听输入框的输入事件,根据输入框的scrollHeight属性来动态设置textarea的高度。具体实现方法如下:

const textarea = document.getElementById('chat-gpt-input');

textarea.addEventListener('input', function() { this.style.height = 'auto'; this.style.height = this.scrollHeight + 'px'; });

这样,就可以实现textarea的高度自适应并且不受最大高度限制,可以自由拉伸

我需要 textarea样式高度自适应并且不会受到最大高度的限制可以自由拉伸!doctype htmlhtml lang=en head meta charset=UTF-8 meta name=viewport content=width=device-width initial-scale=10 titleChatGpT VIP版 - 无涯工作室title link

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

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