javascript 如何使用 jQuery 隐藏和显示 CKEditor?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3269456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide and show a CKEditor using jQuery?
提问by fabien7474
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.
谢谢你。
采纳答案by fabien7474
回答by Peyote
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();
回答by Ross
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();
}
回答by beobeo88
<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>
回答by spinon
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();
}
回答by shox
Try wrapped it in a div eg : <div id="fckz"> <form >...</form> </div>and make the hide show on the div .
尝试将其包裹在 div 中,例如:<div id="fckz"> <form >...</form> </div>并使隐藏显示在 div 上。
回答by Imdadul Huq Naim
$("div[id*='cke_editor']").hide();
$("div[id*='cke_editor']").show();
For my CkEditor 4
对于我的 CkEditor 4

