【发布时间】:2021-12-30 10:07:49
【问题描述】:
我正在尝试在 React 应用程序中使用 JavaScript 自动扩展(向上)文本框。得到这个错误。也尝试使用 window.getElementbyId 代替,但这不起作用。
[![error image][1]][1]
<ReactTextareaAutocomplete
id="textbox"
className="message-input"
placeholder="Type your message.."/>
const tx = document.getElementsByTagName("ReactTextareaAutocomplete");
const maxheight = 100;
const normalheight = window.getComputedStyle(tx[0]).getPropertyValue('height').replace("px", "");
for (let i = 0; i < tx.length; i++) {
tx[i].setAttribute("style", "margin-top:-3px;" + "height:" + (tx[i].scrollHeight > maxheight ? maxheight : tx[i].scrollHeight) + "px;overflow-y:hidden;");
tx[i].addEventListener("input", OnInput, false);
}
function OnInput() {
this.style.marginTop = (normalheight - this.style.height.replace("px", "")) + "px";
this.style.height = "auto";
this.style.height = (this.scrollHeight > maxheight ? maxheight : this.scrollHeight) + "px";
}
[1]: <https://i.stack.imgur.com/1UbRS.png>
【问题讨论】:
标签: javascript html reactjs react-native javascript-objects