皆さんに質問があります。私が記事を書いているとしましょう。10 個のキーワードがあり、テキストで言及する必要があります。キーワードが言及されている場合、この単語がテキストに含まれていた回数を数える必要があります。そして、すべての金額は、テキストエリアの上部または下部に表示する必要があります。たとえば、スパンや入力など、問題ではありません。しかし、どのように?
アップデート:
申し訳ありませんが、テキストエリアに入力するときにやりたいことを忘れていました.jqueryで作成する必要があります。
function ck_jq()
{
var charsCount = CKEDITOR.instances['article'].getData().replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi, '').replace(/^\s+|\s+$/g, '');
var wordCount = CKEDITOR.instances['article'].getData().replace(/[^\w ]/g, "").split(/\s+/);
var max = <?php echo $orderInfo->wordstarget; ?>;
//var max = 5;
if (wordCount >= max) {
var over = max - wordCount.length;
$("#wordstarget").css('color', 'red');
$("#characterscount").css('color', 'red');
$("#words").css('color', 'red');
$("#wordsleft").css('color', 'red');
// $("#wordscount").text(len.length + " characters and \n" + wordCount + " words in this text. Words target: " + max +". Words left: "+ char);
$("#wordstarget").text(max + " words target");
$("#characterscount").text(charsCount.length + " characters");
$("#words").text(wordCount.length + " words");
$("#wordsleft").text(over +" words left");
//$("#wordscount").css('color', 'red');
//$("#wordscount").text(len.length + " characters and \n" + wordCount + " words in this text. Words target: " + max +". Words left: "+ over);
} else {
var char = max - wordCount.length;
$("#wordstarget").css('color', 'green');
$("#characterscount").css('color', 'green');
$("#words").css('color', 'green');
$("#wordsleft").css('color', 'green');
// $("#wordscount").text(len.length + " characters and \n" + wordCount + " words in this text. Words target: " + max +". Words left: "+ char);
$("#wordstarget").text(max + " words target");
$("#characterscount").text(charsCount.length + " characters");
$("#words").text(wordCount.length + " words");
$("#wordsleft").text(char +" words left");
}
}
これを使用して、単語と文字だけを数えます。CKEDITOR.instances['article'].getData()
これを使用して、すべての ckeditor テキストを取得し、正確な単語を検索できます。