检测CKEditor的焦点

时间:2014-09-14 22:43:32

标签: javascript jquery html ckeditor

尝试解决问题,在IOS设备上键盘会破坏固定元素。

当点击CKEditor文本区域时,我的目标是将固定元素的样式设置回固定。

不知道如何检测CKEditor是否正在聚焦。

我没有尝试过,但这是基本的:

http://jsfiddle.net/B4yGJ/180/

CKEDITOR.replace('editor1');

$('#editor1').focus(function() {
  alert('Focused');
});

3 个答案:

答案 0 :(得分:11)

CKEditor有一个自定义焦点事件,对您有用。请参阅此处的文档:http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-focus

你可以这样使用它,例如:

CKEDITOR.on('instanceReady', function(evt) {
    var editor = evt.editor;
    console.log('The editor named ' + editor.name + ' is now ready');

    editor.on('focus', function(e) {
        console.log('The editor named ' + e.editor.name + ' is now focused');
    });
});

CKEDITOR.replace('editor1');

JSFiddle http://jsfiddle.net/B4yGJ/181/

答案 1 :(得分:0)

上述解决方案不适用于我的情况

这是我在深入研究 CKEditor 文档后解决的方法

if(CKEDITOR.instances['editor1'].focusManager.hasFocus) {
    alert('is focused');
}

希望这对有类似问题的人有所帮助。

答案 2 :(得分:-1)

enter image description here   实际上jquery隐藏了你的'#editor1' 编辑器并创建了新的jquery编辑器。但仍然触发了隐藏的文本编辑器(#editor)。 多数民众赞成你没有得到警报框