我想获取文本区域中的字数,并根据字数对我的用户帐户进行更改例如:一个人写了1000个单词,其信誉在帐户中上升(我使用Django)
<!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>
只需将文本分成一个列表并获取其长度。