javascript - 字符有限
问题描述
在 HTML < p > 上限制字符的最短方法是什么?我想让元素输入,并删除边框、背景等,看起来就像纯文本和 maxlength = 5; 但我想知道是否有其他解决方案。谢谢你!
let recipeNameShow = document.createElement('p');
recipeNameShow.classList.add('fntColor');
recipeNameShow.id = 'recipeNameShow';
recipeNameShow.innerText = newRecipeName;
解决方案
如果您不期望用户输入,您可以使用substr
:
let recipeNameShow = document.createElement('p');
recipeNameShow.classList.add('fntColor');
recipeNameShow.id = 'recipeNameShow';
recipeNameShow.innerText = newRecipeName.substr(0,5);
推荐阅读
- android - Android - 未找到本机方法的实现,即使在调用 loadLibrary 之后也是如此
- php - SQL 使用 group_concat
- python - 在python中单击时发送额外的点击
- python - (Python)如何创建一个函数来计算随机列表中特定数字的数量?
- ios - 如何禁用屏幕 iOS 捕获
- r - R,“%>%”符号重叠错误,“[[x]] 仅在具有所有数值变量的数据帧上定义”
- c++ - C++ Primer 第 5 版第 16.5 章类模板专业化
- java - 正则表达式检查单词是否有重复字母并防止输入字符或符号
- testing - 如何在 Visual Studio 2019 中使用 Specflow 配置魅力报告
- r - 错误:“条件长度 > 1,仅使用第一个元素”