在改变事件为ckeditor

时间:2014-09-20 09:25:01

标签: javascript jquery ckeditor

我想将以下函数绑定到我的CKEditor textarea上的任何更改。我目前正在使用4.2版。我添加了onChange CKEditor插件,但我的问题是我似乎无法绑定到formUnloadPrompt()。

这是我的jQuery函数:

function formUnloadPrompt(formSelector) {
    var formA = $(formSelector).serialize(), formB, formSubmit = false;

    // Detect Form Submit
    $(formSelector).submit( function(){
        formSubmit = true;
    });

    // Handle Form Unload
    window.onbeforeunload = function(){
        if (formSubmit) return;
        formB = $(formSelector).serialize();
        if (formA != formB) return "Your changes have not been saved.";
    };

    // Enable & Disable Submit Button
    var formToggleSubmit = function(){
        formB = $(formSelector).serialize();
        $(formSelector+' [type="submit"]').attr( "disabled", formA == formB);
    };

    formToggleSubmit();
    $(formSelector).change(formToggleSubmit);
    $(formSelector).keyup(formToggleSubmit);
}

$(function(){
    formUnloadPrompt('#form');
});

我的CKEditor代码

CKEDITOR.instances['frm_content'].on( 'change', function(e) {
    console.log(e);
    var inst = CKEDITOR.instances['frm_content'];
    if (inst.getData() != '') {
        $('[type="submit"]').removeAttr('disabled');
    } else {
        $(' [type="submit"]').attr('disabled', 'disabled');
    }

});

0 个答案:

没有答案