小编Bha*_*ani的帖子

获取tinymce中的单词数

我在 tinymce 之外有一个字数统计 div,它显示字数但没有使用 wordCount 插件,而是使用正则表达式来计算字数。

但是当我添加项目符号或对已经输入的文本应用粗体时,这个计数没有显示正确的值[它显示计数为 3,而我在使用项目符号时只输入了一个单词,并在突出显示的同时将计数增加 2输入文本]

当使用粗体或斜体、下划线或项目符号或使用 wordCount 插件在 stauts 栏外使用它的输出时,任何人都可以建议在正则表达式中做什么以获得正确的计数[在这种情况下在我的字数 div]

这是代码:

tinymceConfig = {
mode:"exact",
elements:"essay",
menubar: false,
statusbar: false,
plugins: "autoresize",
content_css : '../../theme/css/Language/editor.css',
toolbar : "bold italic underline bullist",
resize:"height",
autoresize_max_height: 325,
setup : function(editor) {
    if ($('#essay').prop('readonly')) {
        editor.settings.readonly = true;
    }

    editor.on('keydown', function (evt) {
       var wordCount = 0;
       var valid_keys = [8, 46];
       text = editor.getContent().replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
       text = text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
       wordCount = text.split(' ').length-1;

       if(wordCount …
Run Code Online (Sandbox Code Playgroud)

javascript regex tinymce word-count

4
推荐指数
1
解决办法
4310
查看次数

标签 统计

javascript ×1

regex ×1

tinymce ×1

word-count ×1