【发布时间】:2011-10-03 18:50:25
【问题描述】:
我们有一个包含很多文本区域的表单(在某些情况下,多达 20 个)。这些文本区域中的每一个都通过 TinyMCE jquery 插件转换为所见即所得的编辑器,如下所示:
var tinymceoptions = {
script_url: '/Scripts/tiny_mce/tiny_mce.js',
theme: "advanced",
mode: "textareas",
elements: "text,html1",
theme_advanced_buttons1: "bold,italic,underline,formatselect,separator,image,insertfile,separator,blockquote,bullist,numlist,separator,undo,redo,separator,link,unlink,separator,code,insertimage",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_blockformats: "h1,h2,h3,p",
width: '100%',
content_css: Settings["tiny_mce_css"],
plugins: "advimage,advlink,autoresize,inlinepopups,imagemanager,paste",
relative_urls: false,
forced_root_block: false
};
$('textarea.editor').tinymce(tinymceoptions);
我们遇到的问题是大约 95% 的时间,textareas 没有在表单 POST 之前使用所见即所得的内容进行更新。在提交表单之前,我们甚至尝试通过循环每个 mce 编辑器并调用 save() 方法来强制保存:
$('textarea.editor').each(function () {
$(this).tinymce().save();
});
用 Fiddler 再次检查 POST,我发现 textarea 仍然没有被更新为适当的值。
有人知道是什么原因造成的吗?
更新
为了让事情更...有趣...我添加了以下回调,但我得到了奇怪的结果。当表单发布 WORKS 时,getContent() 的值在我每次按下一个键时都会发生变化。当表单发布不起作用时,无论我输入多少内容,getContent 都会不断返回初始值:
setup: function (ed) {
ed.onSaveContent.add(function (ed) {
console.debug('save content: ' + $(this).tinymce().getContent());
});
ed.onKeyPress.add(function (ed, e) {
console.debug('Editor contents was modified. Contents: ' + $(this).tinymce().getContent());
});
}
更新 2
越来越近了?我发现清除缓存似乎可以暂时“解决”问题。后续访问将显示损坏的行为。
【问题讨论】:
标签: jquery jquery-plugins tinymce