1

我的网站上有 TinyMCE,效果很好。

最近我添加了只读切换的功能。对于只读切换,我添加了一个字段“mytext_readonly”。TinyMCE 初始化为只读模式,如果“mytext_readonly”中的值为“只读”,则保持只读状态,否则变为可编辑。

该功能按我的意愿工作,除了文本计数器不工作。问题是 onKeyUp 事件不起作用。如果我单击B I U工具栏上的 etc,则文本计数器有效(意味着 onExecCommand 正在工作)

我想知道为什么onKeyUp不工作?我该怎么做才能让它发挥作用?

tinyMCE.init({
mode : "exact",
elements : "mytext",
debug : false,
nowrap : false,
cleanup_on_startup : true,
fix_nesting : true,
force_br_newlines : true,
force_p_newlines : false,
gecko_spellcheck : true,
forced_root_block : '' ,
readonly : true,
setupcontent_callback : "myCustomSetupContent",
plugins : "preview",
plugins : "AtD,preview",
atd_button_url              : "/tinymce-new/jscripts/tiny_mce/plugins/atd-tinymce/atdbuttontr.gif",
atd_css_url                 : "/tinymce-new/jscripts/tiny_mce/plugins/atd-tinymce/css/content.css",
tab_focus : ':next',
theme : "advanced",
theme_advanced_buttons1_add : "AtD",
theme_advanced_buttons1 : "bold,italic,separator, justifyfull,bullist,numlist,|,charmap,|,undo,redo,|",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
/* the URL of proxy file */
atd_rpc_url                 : "/common-scripts/tinymce-new/jscripts/tiny_mce/plugins/atd-tinymce/server/proxy.php?url=",
/* set your API key */
atd_rpc_id                  : "flinstone",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
valid_elements : ""
+"p,"
+"br,"
+"i/em,"
+"ul,"
+"li,"
+"ol,"
+"b/strong,"
+"marquee,"
+"sub,"
+"sup,"
+"table[border|width|height|align],"
+"tr[rowspan|width|height|align|valign],"
+"th,"
+"td[colspan|rowspan|width|height|align|valign]",

setup : function(ed) {
        ed.onKeyUp.add(function(ed) {
            textCounter('mytext','Charcount',4000);
        });

        ed.onExecCommand.add(function(ed) {
            textCounter('mytext','Charcount',4000);
        });
    }
});

function myCustomSetupContent(editor_id, body, doc) {
var desc = document.getElementById('item_description').value;
desc = unescape(desc);
if (desc)
{
    desc = desc.replace(/''/ig,"'");
    desc = desc.replace(/&/ig,'&');
    tinyMCE.get('mytext').setContent(desc);
}

textCounter('mytext','Charcount',4000);
if (document.getElementById('mytext_readonly') && document.getElementById('mytext_readonly').value == 'readonly') {
    //do nothing
}
else
    tinyMCE.get('mytext').getBody().setAttribute('contenteditable', true);
}
4

0 回答 0