如何以编程方式确定CKEditor实例的名称 [英] How to programmatically determine name of CKEditor instance

查看:93
本文介绍了如何以编程方式确定CKEditor实例的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的ASP.NET页面的代码后面以编程方式添加了一个CKEditor实例:

I've added a CKEditor instance programmatically to my page in the code-behind of my ASP.NET page:

VB.NET:

itemEditor = New CkEditor
cell.Controls.Add(itemEditor)

...效果很好。我可以得到回传的HTML,并做它的东西。

... which works fine. I can get the HTML on the postback and do stuff with it.

但是,我也想做一些客户端的东西,特别是一个选定的项目,并通过处理 onchange 事件将其插入到文本中。

However, I also want to do some client-side stuff with it, specifically take a selected item out of another control, and insert it into the text by handling the onchange event.

在JavaScript中的编辑器实例的名称,这样我可以做类似的东西:

So, how can I get the name of the editor instance in the JavaScript, so that I can do stuff like:

function GetCkText()
{
    var htmlFromEditor = CKEDITOR.instances['editorName'].getData();
    // do stuff with htmlFromEditor
}


推荐答案

假设您只有一个编辑器实例:

Assuming you only have one editor instance:

for ( var i in CKEDITOR.instances ){
   var currentInstance = i;
   break;
}
var oEditor   = CKEDITOR.instances[currentInstance];

这里是JavaScript API所说的实例

Here is what the JavaScript API says about instances.

这里是另一种定义CKEditor的方法。这里的'fck'是输入字段id:

Here is another way of defining the CKEditor. Here 'fck' is the input fields id:

CKEDITOR.replace( 'fck', {
    customConfig : prefix + 'js/ckeditor/config.js',
    height: 600,
    width: 950
});

editor = CKEDITOR.instances.fck;


$ b

Notice how I am then able to reference the instance using .fck.

这篇关于如何以编程方式确定CKEditor实例的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆