javascript - How to only show few characters when pasting text in editor?
问题描述
trying to paste characters and if it is more than 50 characters ONLY show the first 50 characters. Can anyone tell me what I'm missing?
Here's my code: LIVE DEMO
CKEDITOR.instances.foo.on('paste',function(event){
alert('paste');
var deleteKey = 46;
var backspaceKey = 8;
var keyCode = event.data.keyCode;
if (keyCode === deleteKey || keyCode === backspaceKey)
return true;
else
{
var textLimit = 50;
var str = CKEDITOR.instances.foo.getData();
if (str.length >= textLimit)
// Need to add code here to only show the first 50 characters
return false;
}
});
解决方案
您可以使用的WORDCOUNT
插件,CKEditor
您可以找到示例
推荐阅读
- reactjs - 如何在 NPM 启动脚本中设置 React 应用程序变量
- javascript - 如何在javascript中自动求和多个输入框内循环
- django - django 超级用户的名字和姓氏可以更新吗?如果是,我该怎么做?
- tree - Prolog:仅使用纯递归计算父级的直接子节点
- javascript - 使用 JSON 和 JavaScript 创建动态多维数组
- windows - 如何使批处理文件创建仍然可以包含百分比值的批处理文件
- sql - 如何在sql中将列转换为行
- c# - 无法使用实体框架连接到 mysql 数据库
- node.js - 修改节点模块有什么后果?
- python - 对二维数组中的坐标进行单独操作