CKEditor插入HTML [英] CKEditor Insert HTML

查看:786
本文介绍了CKEditor插入HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 在我的js文件中,我想更改我的CKEditor文本编辑器的值。

  • 我的值是原始html。

  • 我希望将这个原始值写入空的CKEditor文本编辑器中。

  • 我试过这些,但一直都有一个未定义的函数错误:

      CKEDITOR.instances .myEditorID.insertHtml('< p>这是一个新段落。< / p>'); 
    CKEDITOR.instances.myEditorID.setData('< p>这是编辑器数据。< / p>');

    我也试过,但仍未定义函数错误:

      CKEDITOR.instances.YOUREDITORID.updateElement(); 
    alert(document.getElementById('YOUREDITORID').value);

    代替myEditorID,我尝试了'editor','editor1','editor2',但仍然没有为我工作。



    预先致谢。

    < - >更新---



    这是我的ckeditor文本编辑器的html:

     < textarea id = myEditorIDname =myEditor>< / textarea> 
    < script type =text / javascript>
    $(function(){
    var myEditor = $('#myEditorID');
    myEditor.ckeditor({
    height:200,
    extraPlugins:'charcount ',
    maxLength:2000,
    toolbar:'TinyBare',
    toolbar_TinyBare:[
    ['Bold','Italic','Underline'],
    [ '撤销','重做'],['剪切','复制','粘贴'],
    ['NumberedList','BulletedList','表'],['CharCount']
    ('key',function(obj){
    if(obj.data.keyCode === 8 || obj.data.keyCode === 46){
    return true;
    }
    if(myEditor.ckeditor()。editor.document.getBody()。getText()。length> = 2000){
    alert('您已达到最大字符长度');
    返回false;
    }
    });
    });
    < / script>


    解决方案


    尝试'编辑','editor1','editor2',但仍然
    不适合我。


    查看页面的HTML并查看编辑器的ID字段。它会是这样的

     < textarea id =my_editor>< / textarea> 

    这个id属性是这里需要去的内容

      CKEDITOR.instances.my_editor.insertHtml('< p>这是一个新段落。< / p>'); 


    1. I have a data from database.
    2. In my js file, I would like to change my CKEditor text editor's value.
    3. My value is raw html.
    4. I want this raw value to be written on an empty CKEditor text editor.

    I tried these but got an undefined function error all the time :

    CKEDITOR.instances.myEditorID.insertHtml( '<p>This is a new paragraph.</p>' );
    CKEDITOR.instances.myEditorID.setData( '<p>This is the editor data.</p>' );
    

    I tried this too but still undefined function error :

    CKEDITOR.instances.YOUREDITORID.updateElement();
    alert( document.getElementById( 'YOUREDITORID' ).value );
    

    Instead of myEditorID i tried 'editor', 'editor1', 'editor2' but still doesn't work for me.

    Thanks in advance.

    ---Update---

    This is the html of my ckeditor text editor :

    <textarea id="myEditorID" name="myEditor"></textarea>
    <script type="text/javascript">
        $(function () {
            var myEditor = $('#myEditorID');
            myEditor.ckeditor({ 
            height: 200, 
            extraPlugins: 'charcount', 
            maxLength: 2000, 
            toolbar: 'TinyBare', 
            toolbar_TinyBare: [
                 ['Bold','Italic','Underline'],
                 ['Undo','Redo'],['Cut','Copy','Paste'],
                 ['NumberedList','BulletedList','Table'],['CharCount']
            ] 
            }).ckeditor().editor.on('key', function(obj) {
                if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
                    return true;
                }
                if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2000) {
                    alert('You have reached the maximum char length');
                    return false;
                }
            });
        });
    </script>
    

    解决方案

    Instead of myEditorID i tried 'editor', 'editor1', 'editor2' but still doesn't work for me.

    You need to look at the HTML of your page and see what the ID field is for your editor. It will be something like this

    <textarea id="my_editor"></textarea>
    

    That id attribute is what needs to go in here

    CKEDITOR.instances.my_editor.insertHtml('<p>This is a new paragraph.</p>');
    

    这篇关于CKEditor插入HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆