仅在CKEditor初始化后运行JavaScript函数

J86*_*J86 2 javascript partial-views ckeditor asp.net-mvc-4

我在ASP.NET MVC应用程序中工作.该应用程序有一个表单,通过@Ajax.ActionLink这个表单引入,这个表单有一个textarea,我绑定CkEditor.

我有一些特定的要求,包括抓住用户在CKEditor中键入的内容,并按下按钮传递到某个地方.

所以我目前正在做的是将onChange事件绑定到CKEditor,假设我在CKEditor textarea中更改了某些内容,这可以正常工作.

但是,如果用户获取表单,不更改任何内容,然后按下按钮以获取内容该怎么办.它不会起作用,因为我的代码只会在某些内容发生变化后抓取.所以我的问题是,我该如何运行以下内容:

/*
* As the user types the email body insert, this function updates the
* value on the hidden input field on [ form#EmailPreviewForm ] above.
*/
var data = CKEDITOR.instances.emailBody.getData();
$('#emailBodyInsert').val(data);
Run Code Online (Sandbox Code Playgroud)

只有在该CKEditor的完成初始化,否则我得到一个错误说undefinedemailBody; 这是有道理的,因为此时CKEditor尚未初始化.

Ser*_*y K 5

使用CKEditor instanceready事件:

CKEDITOR.replace('editor1', {
    on :
    {
        instanceReady : function( ev ) {
            // your code here
        }
    }
} );
Run Code Online (Sandbox Code Playgroud)