当前位置:网站首页>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'
}
},
边栏推荐
猜你喜欢
随机推荐
rxjs Observable of 操作符的单步调试分析
Using securecrtportable to remotely connect virtual machines
【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
Configure filter
Ida dynamic debugging apk
There is no signal in HDMI in computer games caused by memory, so it crashes
Mysql database detailed learning tutorial
2020-ViT ICLR
Basic knowledge of ngnix
内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
Fully annotated SSM framework construction
YOLOv5.5 调用本地摄像头
LC501. 二叉搜索树中的众数
Lc669. Prune binary search tree
聊一聊Zabbix都监控哪些参数
Awoo's favorite problem (priority queue)
Efficiency improvement - encourage personalized container development environment
Origin2018安装教程「建议收藏」
QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
三翼鸟两周年:羽翼渐丰,腾飞指日可待