首页 > 解决方案 > 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;
    }
});

标签: javascript

解决方案


您可以使用的WORDCOUNT插件,CKEditor您可以找到示例

https://ckeditor.com/cke4/addon/wordcount


推荐阅读