我在页面的文本区域上使用 TinyMCE。我正在尝试获取字符和字数并输入文本区域。我一直在尝试各种版本以使其正常工作,但没有成功。这是最新的错误版本:
$().ready(function() {
$('textarea.tinymce').tinymce({
// Location of TinyMCE script
script_url: 'jscripts/tiny_mce/tiny_mce.js',
// General options
theme: "advanced",
plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
// Theme options
theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
// Example content CSS (should be your site CSS)
content_css: "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url: "lists/template_list.js",
external_link_list_url: "lists/link_list.js",
external_image_list_url: "lists/image_list.js",
media_external_list_url: "lists/media_list.js",
// Replace values for the template plugin
template_replace_values: {
username: "Some User",
staffid: "991234"
},
//setup:'tmceWordcount'
setup: function(ed) {
ed.onKeyUp.add(function(ed, e) {
//Following does not work correctly
//var strip = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"");
//Neither does the code below
var strip = (tinyMCE.activeEditor.getContent()).replace(/<[^>]+>/g, "");
var text = strip.split(' ').length + " Words, " + strip.length + " Characters"
tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
});
}
});
});
这是我的例子。我正在输入第一个单词:Me
当我输入第一个单词时,它会正确显示字符和单词。但是当我按空格输入下一个单词时,它显示字符是8。如何?IMO,它也包括 HTML 标签。上述输入文本的 HTML 代码如下:
<p>Me </p>
我希望输出为 1 个单词和 3 个字符(2 个字符 + 1 个空格)。但它向我展示了另外 5 个字符。这是怎么发生的?我该如何阻止它?如果您确实输入了下一个单词,一旦您开始输入,它就会显示正确的字符数。但是当你再次点击空格时,它会添加更多字符。因此,每当按下空格和输入按钮时,似乎都会出现此问题。如何解决这个问题?