[英]Expanding textarea script does not work if is defined the height of textarea
这是我的脚本:
function expandtext(textArea){
while (
textArea.rows > 1 &&
textArea.scrollHeight < textArea.offsetHeight
){
textArea.rows--;
}
var h=0;
while (textArea.scrollHeight > textArea.offsetHeight && h!==textArea.offsetHeight)
{
h=textArea.offsetHeight;
textArea.rows++;
}
textArea.rows++
}
HTML:
<textarea class="expta" onkeyup="expandtext(this);" style="overflow-y:hidden;"></textarea>
到目前为止,一切正常。 但是当我添加textarea高度时:
<textarea class="expta" onkeyup="expandtext(this);" style="height:16px;overflow-y:hidden;"></textarea>
它不起作用了。 有任何想法吗?
如果您为textarea设置了style-height-属性,则在您进行操作之前,此style属性将保持设置为16px。
您需要在脚本中更改textarea.style.height而不是textarea.rows!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.