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

问题描述 投票:2回答:1

我在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);

只有在CKEditor完成初始化之后,因为否则我在undefined上发出错误说emailBody;这是有道理的,因为此时CKEditor尚未初始化。

javascript asp.net-mvc-4 ckeditor partial-views
1个回答
5
投票

使用CKEditor instanceready事件:

CKEDITOR.replace('editor1', {
    on :
    {
        instanceReady : function( ev ) {
            // your code here
        }
    }
} );
© www.soinside.com 2019 - 2024. All rights reserved.