我正在构建一个 javascript 应用程序,它将显示一个实时更新的讨论线程。它会定期轮询服务器以获取新数据,并将其写入页面。对于发表评论和回复,我们正在尝试使用 TinyMCE WYSIWYG 编辑器,它将文本区域转换为一个不错的 HTML 编辑器。这是我第一次使用这个编辑器。该应用程序严重依赖 jQuery,因此我们使用 TinyMCE 的 jQuery 插件使其更易于使用。
这就是问题所在......每次我们的代码生成一个新的文本区域时,我们都会为其附加一个编辑器。第一个出现并完美运行。当我们添加更多时,TinyMCE 代码会隐藏 textarea,但不会生成编辑器,我不知道为什么。
我已经在 jsFiddle 上构建了一个简单的工作示例:
function addTextArea(){
// find where the textareas will be placed
var container = $('#textareaContainer');
container.append( newTextArea() );
container.append( $(document.createElement('hr')) );
}
// define some configuration settings for the editor
var editorConfig = {
// Location of TinyMCE script
script_url: 'http://tinymce.cachefly.net/4.0/tinymce.min.js',
// setup parameters
menubar: false,
statusbar: false,
toolbar: 'bold italic underline | bullist numlist | undo redo | removeformat'
}
function newTextArea(){
var textarea = $(document.createElement('textarea'))
.attr('id',(new Date()).getTime()) // give it a unique timestamp ID
.val( 'This text area added @ ' + new Date() )
.tinymce(editorConfig); // apply the WYSIWYG editor
return textarea;
}
任何帮助,将不胜感激。谢谢你。