根据Textarea的高度和宽度在textarea中设置Max字符 [英] Set Max characters in textarea base on Textarea height and width

查看:55
本文介绍了根据Textarea的高度和宽度在textarea中设置Max字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意事项:我尝试了所有问题&与该主题相关的答案.

Notes: I tried all questions & answers related to this topic.

我想基于Textarea的高度和宽度来限制字符数..假设我已经设置了Textarea height:50px width:60px; ,所以我想在完成Textarea之后防止出现字符.

I want to limit the number of characters Base on Textarea height and width.. suppose I have set Textarea height :50px and width:60px; so i want to prevent character after completed Textarea .

注释:按文本区域 height width 设置最大字符数.

Notes: Set Max characters by Textarea height and width.

相关搜索链接

  1. > limit-height-of-textarea-based-on-content a>
  2. textarea-character-limit

.textareaClass {
  height: 50px;
  width: 60px;
  resize: none;
  overflow: hidden
}

<textarea class="textareaClass"></textarea>

推荐答案

您可以将 height width 属性设置为ch(字符)单位.并将 maxlength =(width)*(height/line-height)" 属性设置为 textarea .

You can set the height and width property as ch (character) unit. And set maxlength="(width) * (height / line-height)" attribute to textarea.

.textareaClass {
  height: 10ch;
  width: 10ch;
  line-height: 2ch;
  resize: none;
  overflow: hidden
}

<!-- max-length should be 10 (width) * 10 (height) / 2 (line-height) = 10 * 5 = 50 -->
<textarea class="textareaClass" maxlength="50"></textarea>

这篇关于根据Textarea的高度和宽度在textarea中设置Max字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆