gpt4 book ai didi

javascript - 按类调用CKEditor

转载 作者:数据小太阳 更新时间:2023-10-29 03:59:49 24 4
gpt4 key购买 nike

我需要自动调用 CKEditor 的多个实例...实际上我使用了函数:

CKEDITOR.replace( 'editor1');

其中“editor1”是我要显示我的 CKEditor 的 div 的 ID 名称。

我正在使用 jQuery 来自动化这个过程,我需要使用“class”标签而不是 id。

特别是我有这个 html:

<div class="CKEditor">
<div class="text">
mytext
</div>

<p style="text-align:center" class="buttons">
<input type="button" value="edit" class="button_edit">
<input type="button" value="preview" class="button_preview" style="display:none">
</p>

<div class="editor" >
</div>

</div>

和这个 jQuery 脚本:

$(function() 
{
$('.CKEditor').each(function()
{
var __main = $(this);
var __buttons = __main.children('.buttons');
var __text = __main.children(".text");
var editor;

__buttons.children('.button_edit').click(function()
{
__text.hide();
if (editor) return;

editor = CKEDITOR.replace("editor");
editor.setData(__text.html());

if(editor)
{
__buttons.children('.button_edit').hide();
__buttons.children('.button_preview').show();
}
});

__buttons.children('.button_preview').click(function()
{
__text.show();
__text.html(editor.getData());

if ( !editor ) return;

editor.destroy();
editor = null;
__buttons.children('.button_edit').show();
__buttons.children('.button_preview').hide();
__main.children("#editor").html("");
});
});
});

是否可以不修改CKEDITOR的源码?


编辑

我找到了解决方案:

1) html 变成:

<div class="editor" id="edt1"></div>

2) 在 JQuery 中:

var __editorName = __main.children('.editor').attr('id');

然后我调用 CKEditor:

editor = CKEDITOR.replace(__editorName);

=) =)

最佳答案

<!DOCTYPE HTML>
<html>
<head>
<script src="ckeditor.js"></script>
<script>
$(document).ready(function() {
CKEDITOR.replaceClass = 'ckeditor';
});
</script>
</head>
<body>
<div>
<textarea class="ckeditor" cols="80" name="content"></textarea>
</div>
<div>
<textarea class="ckeditor" cols="80" name="content"></textarea>
</div>
</body>
</html>

关于javascript - 按类调用CKEditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14021825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com