使用字数统计插件获取tinymce中的字数

问题描述 投票:-1回答:1

我想获取文本区域中的字数,并根据字数对我的用户帐户进行更改例如:一个人写了1000个单词,其信誉在帐户中上升(我使用Django)

python django tinymce tinymce-4 django-tinymce
1个回答
0
投票
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>

    <script>
      tinymce.init({
        selector: "textarea",  // change this value according to your HTML
        plugins: "wordcount",
        toolbar: "wordcount"
      });

我用这个,但是出现错误TypeError:tinymce.activeEditor为空

**var wordcount = tinymce.activeEditor.plugins.wordcount;

console.log(wordcount.body.getWordCount());
console.log(wordcount.body.getCharacterCount());
console.log(wordcount.body.getCharacterCountWithoutSpaces());

console.log(wordcount.selection.getWordCount());
console.log(wordcount.selection.getCharacterCount());
console.log(wordcount.selection.getCharacterCountWithoutSpaces());

**

  </head>

  <body myFunction()>
    <form method="post">
      <textarea id="mytextarea"></textarea>
    </form>
  </body>
</html>

-1
投票

只需将文本分成一个列表并获取其长度。

© www.soinside.com 2019 - 2024. All rights reserved.