使用jQuery隐藏TinyMCE

238*_*890 7 javascript jquery wysiwyg tinymce jquery-plugins

我里面有一个TinyMCE textarea #container

当我使用$('#container').hide()然后$('#container').show(),tinyMCE抛出:

无法读取未定义的属性"选择"

我正在使用jquery插件,所以这就是我设置它的方式:

$('#container textarea').tinymce({ /* options */ });
Run Code Online (Sandbox Code Playgroud)

我应该做些什么呢?

Tha*_*ama 10

这里使用的正确命令是

// editor_id is the id of your textarea and 
// tinymce will use this id to uniquely identify this editor instance
editor_id = $("#container textarea").attr('id');
tinymce.get(editor_id).hide();  
Run Code Online (Sandbox Code Playgroud)

让它再次可见使用

tinymce.get(editor_id).show();
Run Code Online (Sandbox Code Playgroud)


Chr*_*ker 0

不要隐藏它,而是尝试将其发送到屏幕之外 - 例如:

$('#container').css('left', '-1000px');
Run Code Online (Sandbox Code Playgroud)

编辑/更新:

您还可以尝试在 hide() 容器之前从文本区域中删除 TinyMCE,然后在 show() 后将其恢复。但你需要给你的文本区域一个#ID:

//To Enable
tinyMCE.execCommand('mceAddControl', false, $("#container textarea").attr('id'));
//To Disable
tinyMCE.execCommand('mceRemoveControl', false, $("#container textarea").attr('id'));
Run Code Online (Sandbox Code Playgroud)