CKEditor key event not updating text properly

南笙酒味 提交于 2020-01-02 07:19:21

问题


I have the following code to automatically update the content inside a div when the user types it inside a CKEditor textarea:

CKEDITOR.instances.editor.on("key", function(e)
{
    var preview = document.getElementById('some-div');
    preview.innerHTML = CKEDITOR.instances.editor.getData();
});

The problem is that if I type in "Hello world", in the div it appears "Hello worl" and the "d" doesn't appear until another key is pressed. And I would want the same content in both places. Thanks in advance!


回答1:


I solved it handling the key event in a different way. You can see it below:

CKEDITOR.instances.editor.on('contentDom', function() 
{
    CKEDITOR.instances.editor.document.on('keyup', function(event) 
    {
        var preview = document.getElementById('some-div');
        preview.innerHTML = CKEDITOR.instances.editor.getData();
    });
});


来源:https://stackoverflow.com/questions/24808029/ckeditor-key-event-not-updating-text-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!