简体   繁体   English

如何使用jQuery隐藏和显示CKEditor?

[英]How to hide and show a CKEditor using jQuery?

The following code should allow to hide/show the CKEditor form 以下代码应允许隐藏/显示CKEditor表单

<a onClick="$('#form1').hide();">Hide</a>
<a onClick="$('#form1').show();">Show</a>
<form action="sample_posteddata.php" method="post" id="form1">
    <textarea id="editor1" name="editor1">blabla</textarea>
    <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script>
    <input type="submit" value="Submit" />
</form>

However, this code works fine on Chrome but on Firefox, once I have toggled once the editor (one 'hide' click followed by one 'show' click) , it becomes not editable !! 但是,这个代码在Chrome上工作正常但在Firefox上,一旦我切换了一次编辑器(一个'隐藏'点击后跟一个'显示'点击),它变得不可编辑!

How can I make it work on every browser? 如何让它在每个浏览器上运行?

Thank you. 谢谢。

I found an answer at http://dizkover.com/post/67/how-to-show-hide-ckeditor-using-jquery-ckeditor-tip 我在http://dizkover.com/post/67/how-to-show-hide-ckeditor-using-jquery-ckeditor-tip找到了答案

So basically, you have to destory the CKEditor instance first by doing the ff: 所以基本上,你必须首先通过执行ff来破坏CKEditor实例:

if(typeof CKEDITOR.instances['element_name'] != 'undefined') {
    CKEDITOR.instances['element_name'].updateElement();
    CKEDITOR.instances['element_name'].destroy();
}

Solution is: 解决方案是:

// Hide form
CKEDITOR.instances.editor1.updateElement();
CKEDITOR.instances.editor1.destroy();
$('#form1').hide();
//Show form
CKEDITOR.replace( 'editor1', {height: "220px", skin: "v2"});
$('#form1').show();
<div id="container">            
    <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"></textarea>
</div>
<p>
    <input type="button" value="jQuery Hide" onclick="$('#container').hide('fast');" />
    <input type="button" value="jQuery Show" onclick="$('#container').show('fast');" />
</p>

Looks like this might help you out: 看起来这可能会帮助你:

http://dev.ckeditor.com/ticket/544 http://dev.ckeditor.com/ticket/544

In the report I linked to they show trying something like this: 在我链接的报告中,他们显示尝试这样的事情:

if (frames[0]) {
  frames[0].FCK.EditingArea.MakeEditable();
}

It doesn't seem to have a real workaround. 它似乎没有真正的解决方法。

See here for more info. 有关详细信息,请参见此处 The only solution is to wait for CKEditor new version 3.4. 唯一的解决方案是等待CKEditor新版本3.4。

尝试将其包装在div中,例如: <div id="fckz"> <form >...</form> </div>并在div上进行隐藏显示。

$("div[id*='cke_editor']").hide();

$("div[id*='cke_editor']").show();

For my CkEditor 4 对于我的CkEditor 4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM