angularjs - 如何在 angularJS 中将羽毛笔编辑器的文本字符限制限制为最多 5000 个字符?
问题描述
这是我的html代码。我如何限制用户输入最多 5000 个字符。
<div class="ql-container ql-bubble" id="richTextQuel">
<ng-quill-editor theme="bubble" id="richTextEditor" placeholder="Inclusions" ng-model="title" modules="richTextEditorModules" class="ng-pristine ng-untouched ng-valid ng-isolate-scope
ng-not-empty">
</ng-quill-editor>
</div>
解决方案
这是 Angular 2+ 和 PrimeNG 的解决方案,但您可以更改它以适合您的解决方案:
this.editor.getQuill().root.addEventListener('keydown', ($event) => this.checkLength($event));
其中 checkLength 是:
checkLength($event) {
if (this.editor.getQuill().root.innerHTML.length >= 15) {
$event.preventDefault();
}
}
推荐阅读
- office-ui-fabric - 由于结构中的一些问题,单元测试用例在我的 React 应用程序中失败
- c# - Xamarin Android 绑定库 - 未在 DigitalPersona UareU JAR 中实现继承的抽象成员
- laravel - 使用 make:request 的自定义验证返回未找到控制器
- react-native - React Native:绘制精确适合给定矩形的文本
- latex - 周围标志乳胶
- reactjs - 在 React Native 中,当 DrawerNavigator 与 StackNavigator 一起使用时,它无法更改 Header 的背景颜色
- javascript - “字符串”类型的参数不能分配给“AbstractControl”类型的参数。角反应形式
- sql - 在 Access 2003 中从 SQL 存储过程创建动态报表
- sql - 如何在 SQL INSERT 中使用整数变量
- extjs - Sencha 键控多对一关系,具有复杂的(命名空间)名称