我在頁面的textarea上使用TinyMCE。我試圖獲得字符和字數,並輸入textarea。我一直在嘗試各種版本,使其正常工作,但沒有成功。這裏是最新的越野車版本: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.如何?國際海事組織,其中也包括HTML標籤。的HTML代碼是上述輸入的文本如下:
<p>Me </p>
我期望輸出是1個字和3個字符(2個字符+ 1個空間)。但它顯示了我5個字符。這是怎麼回事&我該如何阻止它?如果您輸入下一個單詞,只要您開始輸入,就會顯示正確的字符數。但是當你再次擊中空間時,它會添加更多字符。所以這個問題似乎在空間&輸入按鈕被擊中時發生。這怎麼解決?
嗨,感謝您的代碼。我試了上面列出的兩個代碼,同樣的問題仍然存在。出於某種奇怪的原因,它不會刪除HTML標籤。它正在考慮他們。它應該在輸入文本時採用,但是它正在考慮HTML源代碼。我甚至申請了兩次,但效果相同。如果您嘗試使用此代碼,即使在應用替換函數後,您也會看到其提示HTML輸出:'var strip =(tinyMCE.activeEditor.getContent())。替換(/ <\/?[^>] +>/gi,''); \t \t \t \t \t \t警報(strip.replace(/ <\/?[^>] +>/GI, ''));'上的任何想法如何解決這一問題? – Devner 2012-07-06 18:55:31