まず第一に、出力:
var postContent = wysihtml5Textarea.data("wysihtml5").editor.getValue();
次のようになります。
<p>sf sdf asd asd <b>asd</b> d asd ad asd </p>
私は次のことを達成したい:
- すべてのHTMLタグを削除します
- すべて削除する
- 単語を数えます(たとえば、「ロックンロール」のような単語は1つの単語として数える必要があります)。
私はSOをブラウジングしてきましたが、次のことがわかりました。
$(txt).text(); remove all HTML tags
txt.replace(/ /g, ''); // remove all
txt.replace( /[^\w ]/g, "" ).split( /\s+/ ).length; // word count (not sure if it deals with hyphenated words)
$('#word-count').html(wordCount); // and display it
これらすべてをきれいに混ぜる方法がわかりません。
助言がありますか?