当前位置:网站首页>el-input文本域字数限制,超过显示变红并禁止输入
el-input文本域字数限制,超过显示变红并禁止输入
2022-07-01 21:50:00 【1024_Byte】
效果展示
代码:
<el-form-item label="养护要点说明:" prop="remark" :rules="[{ required: true, message: '不能为空' }]">
<el-input
type="textarea"
@input="timeEffectInput" // 输入事件(在这处理限制)
maxlength="200" // 最大字数限制
resize="none" // 控制是否能被用户缩放
show-word-limit // 是否显示输入字数统计
:rows="3" // 自适应内容高度,可传入对象,如,{ minRows: 2, maxRows: 6 }
style="width: 92%"
v-model="dialogForm.remark"
placeholder="请输入养护要点说明!"
></el-input>
</el-form-item>
timeEffectInput() {
const length = this.dialogForm.remark.length // 先拿到当前输入时文本域文字长度
if (length >= 200) {
// 当长度超过200
// 获取文本域计数统计设置字体为红色
this.$el.querySelector('.el-input__count').style = 'color:red !important'
// 防止后续输入溢出截取0-200的字符
this.dialogForm.remark = this.dialogForm.remark.substr(0, 200)
} else {
// 不超过则设置为原字体颜色
this.$el.querySelector('.el-input__count').style = 'color:#909399 !important'
}
},
边栏推荐
- 隐藏用户的创建和使用
- 104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
- CIO's discussion and Analysis on the definition of high-performance it team
- Fiori 应用通过 Adaptation Project 的增强方式分享
- 人体姿态估计的热图变成坐标点的两种方案
- FFMpeg学习笔记
- 13th Blue Bridge Cup group B national tournament
- [literacy] deep / shallow, local / global features in machine learning image processing
- 内部字段分隔符
- 104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
猜你喜欢
随机推荐
Niuke monthly race - logarithmic sum in groups
awoo‘s Favorite Problem(优先队列)
Single step debugging analysis of rxjs observable of operator
Explain kubernetes network model in detail
效率提升 - 鼓捣个性化容器开发环境
Rust语言——小小白的入门学习05
Selection of all-optical technology in the park - Part 2
SAP 智能机器人流程自动化(iRPA)解决方案分享
并发编程系列之FutureTask源码学习笔记
Recent public ancestor offline practice (tarjan)
【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
pytorch训练自己网络后可视化特征图谱的代码
Why must digital transformation strategies include continuous testing?
Ffmpeg learning notes
YOLOv5.5 调用本地摄像头
友善串口助手使用教程_友善串口调试助手怎么进行配置-友善串口调试助手使用教程…
Operation category read is not supported in state standby
小红书Scheme跳转到指定页面
Configure filter
人体姿态估计的热图变成坐标点的两种方案