Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将事件处理程序附加到ClassicEditor_Javascript_Jquery_Ckeditor - Fatal编程技术网

Javascript 无法将事件处理程序附加到ClassicEditor

Javascript 无法将事件处理程序附加到ClassicEditor,javascript,jquery,ckeditor,Javascript,Jquery,Ckeditor,我正在使用CKEditor来允许用户设置post消息的样式,并且我正在使用以下javascript代码来配置我的ClassicEditor: ClassicEditor .create($("#post-message")[0], { language: $("html").attr("lang"), alignment: { options: ['left', 'right'] }, toolbar: ["undo", "redo", "bold

我正在使用CKEditor来允许用户设置post消息的样式,并且我正在使用以下javascript代码来配置我的ClassicEditor:

ClassicEditor
.create($("#post-message")[0], {
    language: $("html").attr("lang"),
    alignment: {
        options: ['left', 'right']
    },
    toolbar: ["undo", "redo", "bold", "italic", "blockQuote", "link", "numberedList", "bulletedList"],
    autoParagraph : false
})
.then(editor => {
    myEditor = editor;
    myEditor.model.document.on('change', (event) => {
        $("#post-message").val(myEditor.getData());
        if (validatePostMessage() == false) {
            $(".ck-content").css("border-color", "red");
        }
        else {
            $(".ck-content").css("border-color", "rgb(196, 196, 196)")
        }

    });
     //this one not working
    myEditor.model.document.on('blur', (event) => {
        alert("hi");

    });
})
.catch(error => {
    console.error(error);
});
当发生更改事件但模糊事件不工作时,上述代码工作

<textarea type="text"
  class="form-control"
  maxlength="2000"
  id="post-message"
  name="post-message">
</textarea>

我的问题是,当编辑器失去焦点时,为什么模糊事件处理程序不工作

附言:

我正在使用以下版本:

您可以在编辑器中使用来确定它是焦点还是模糊

文档中的示例:

editor.editing.view.document.on('change:isFocused', ( evt, data, isFocused ) => {
    console.log( `View document is focused: ${ isFocused }.` );
});
因此,对于您的用例,它将是:

editor.editing.view.document.on('change:isFocused', ( evt, data, isFocused ) => {
    if ( isFocused == false ) // blur
    {
        alert('blur');
    }
});

成功了。所以我应该使用editing.view而不是model.document。