如何以编程方式确定 CKEditor 实例的名称
我已以编程方式将 CKEditor 实例添加到 ASP.NET 页面的代码隐藏中的页面:
VB.NET:
itemEditor = New CkEditor
cell.Controls.Add(itemEditor)
... 工作正常。我可以获取回发的 HTML 并用它做一些事情。
但是,我还想用它做一些客户端操作,特别是从另一个控件中取出选定的项目,并通过处理 onchange
事件将其插入到文本中。
那么,如何在 JavaScript 中获取编辑器实例的名称,以便我可以执行以下操作:
function GetCkText()
{
var htmlFromEditor = CKEDITOR.instances['editorName'].getData();
// do stuff with htmlFromEditor
}
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)
... which works fine. I can get the HTML on the postback and do stuff with it.
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.
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
假设您只有一个编辑器实例:
以下是 JavaScript API 关于 实例< 的说法/a>.
这是定义 CKEditor 的另一种方法。这里“fck”是输入字段 id:
请注意我如何使用
.fck
引用该实例。Assuming you only have one editor instance:
Here is what the JavaScript API says about instances.
Here is another way of defining the CKEditor. Here 'fck' is the input fields id:
Notice how I am then able to reference the instance using
.fck
.如果您只有一个实例并且您不知道它的名称。
If you only have a single instance and you do not know the name of it.
以下代码:
对我来说效果很好。
The following code:
works fine for me.
好吧,我找到了一种方法...但我不太喜欢它...
我在添加编辑器后向页面添加了一个隐藏字段控件,并将编辑器的 ClientId 放入其值中:
.. 和然后在 JavaScript 中,我可以获得隐藏字段,因此编辑器名称如下:
但至少可以说,它有点不优雅。有人有更好的办法吗?
Well I've found a way... but I don't like it much...
I've added a Hidden Field control to the page, after adding the editor, and put the editor's ClientId in its value:
.. and then in the JavaScript, I can get the hidden field, and hence the editor name as follows:
But it's a bit inelegant, to say the least. Anyone got a better way?
如果您使用
CKEDITOR.appendTo(...)
,请记住 ckeditor 会在内部创建实例名称。因此,您可以在创建名称后立即查询该名称,然后将其存储在某处,并在以后使用。顺便说一句:
CKEDITOR.replace(...)
方法允许您定义实例名称(请参阅上面的答案)If you are using
CKEDITOR.appendTo(...)
, keep in mind that the ckeditor does create an instance name internally. So you can query for that name immediately after creating it, then store it somewhere, and use it later.by the way: The
CKEDITOR.replace(...)
method allows you to define an instance name (see answer above)如果您需要来自插件的实例,至少在版本 4+ 中您可以执行此操作。
在这里我想知道我应用 ckeditor 的文本区域的名称。
If you need the instance from a plugin, at least in version 4+ you can do this.
Here I am wanting to know the name of the textarea I applied ckeditor on.