gpt4 book ai didi

javascript - 输入超过最大宽度时动态扩展文本区域的高度

转载 作者:太空宇宙 更新时间:2023-11-04 02:38:07 26 4
gpt4 key购买 nike

当输入超过文本区域元素的最大宽度时,如何水平增加文本区域?我也不想看到水平滚动条。

呈现的 html

<textarea name="CatchPhrase" class="input-validation-error" id="CatchPhrase" aria-invalid="true" aria-required="true" aria-describedby="CatchPhrase-error" rows="2" cols="20" data-val-required="The Catch Phrase field is required." data-val="true" data-val-maxlength-max="50"
data-val-maxlength="The field Catch Phrase must be a string or array type with a maximum length of '50'." htmlattributes="{ id = profileCatchPhrase, class = form-control }">I like yoga sd;lasdlk asdks';aksd'asd 'asd';las ';asd'lasd';las'dl as'dla'sdl'asld as'd;las'dl; a;sdlka;sdklasd ;alsd;lkasda ;alskd;lkasd ;lkasd;lk</textarea>

渲染 HTML 之前

<div class="form-group">
@Html.LabelFor(model => model.CatchPhrase, htmlAttributes: new { @class = "control-label col-lg-2 col-md-2 col-sm-2 col-xs-2" })
<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10">
@Html.TextAreaFor(model => model.CatchPhrase, new { htmlAttributes = new { id = "profileCatchPhrase", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CatchPhrase, "", new { @class = "text-danger" })
</div>
</div>

最佳答案

尝试这样的事情:

$('#CatchPhrase').on('input', function() {
$(this).outerHeight(38).outerHeight(this.scrollHeight);
});

参见:https://stackoverflow.com/a/34513436/4613398

jsfiddle:https://jsfiddle.net/3qmztmjj/

关于javascript - 输入超过最大宽度时动态扩展文本区域的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35262650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com