javascript 查找ckeditor实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11449619/
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
Find ckeditor instance
提问by numfar
I want to access and manipulate the content of a textarea where ckeditor is used. My original code before I started using the editor was:
我想访问和操作使用 ckeditor 的 textarea 的内容。在我开始使用编辑器之前,我的原始代码是:
(function ($) {
"use strict";
$(document).ready(function () {
for(var i=0; i<=10; i++) {
$('#edit-button'+i).click(function(){
var tag = $(this).attr("value");
var id ="edit-body-und-0-value"; /* id of textarea */
var element = document.getElementById(id);
var start = element.selectionStart;
var end = element.selectionEnd;
var text = element.value;
var prefix = text.substring(0, start);
var selected = text.substring(start, end);
var suffix = text.substring(end);
selected = "["+tag+"]" + selected + "[/"+tag+"]";
element.value = prefix + selected + suffix;
element.selectionStart = start;
element.selectionEnd = start + selected.length;
return false;
});
}
});
})(jQuery);
This stops working when the editor is enabled.
当编辑器启用时,这将停止工作。
I'm guessing that I need to use some different object then the 'element' object, the ckeditor object, and then I could maybe use the function described here: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html
我猜我需要使用一些不同的对象,然后是“元素”对象,ckeditor 对象,然后我可以使用这里描述的函数:http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR 。编辑器.html
But how do I get the ckeditor object?
但是我如何获得 ckeditor 对象?
The ckeditor is added in drupal so I know very little about it and I am very unsure about how to access it or what information to look for in order to be able to know what to do.
ckeditor 是在 drupal 中添加的,所以我对它知之甚少,我非常不确定如何访问它或寻找什么信息以便能够知道要做什么。
On this page: http://ckeditor.com/blog/CKEditor_for_jQuery
在此页面上:http: //ckeditor.com/blog/CKEditor_for_jQuery
$( 'textarea.editor' ).ckeditor();
is used to create the object(?). But I already have an ckeditor instance that I need to find. Can I some how select the editor for a given textarea?
用于创建对象(?)。但是我已经有一个我需要找到的 ckeditor 实例。我可以知道如何为给定的 textarea 选择编辑器吗?
回答by Kevin
Using the jquery adapter, you can get the ckeditor "object" like this:
使用 jquery 适配器,您可以像这样获得 ckeditor “对象”:
$('textarea.editor').ckeditorGet()
So to destroy it, you'd do
所以要摧毁它,你会做
$('textarea.editor').ckeditorGet().destroy()
This is using version 4.x of ckeditor.
这是使用 ckeditor 的 4.x 版。