2

如何在 CKEditor 中设置文本?CKEditor 还需要与 ckfinder 集成。

我试着做

// 我需要在后面的代码中设置 ckeditor 文本的值。为了从代码隐藏中获取该值,我使用了一个将在代码后面设置的 div。这目前没有隐藏,但我最终会这样做。我需要将此值设置为我的 ckeditor。

    <textarea id="editor1" name="editor1"></textarea>
        <script type="text/javascript">
            window.onload = function () {

                    var edt = CKEDITOR.replace('editor1', { toolbar: 'Basic' });
 CKFinder.setupCKEditor(edt, '/ckfinder/');

                    var t = <%=editortext.InnerText %>;


                    CKEDITOR.instances.editor1.setData(t);

            }

如果我为 t 放置一些静态文本,则 var t = "Some Text";

然后设置

CKEDITOR.instances.editor1.setData(t); 它工作正常。

如果我使用,

var t = <%=editortext.InnerText %>;


                    CKEDITOR.instances.editor1.setData(t);

ckeditor 不再显示。仅显示文本区域。如何在ckeditor中设置文本?请帮忙

4

4 回答 4

9

此语法在这里可能很有用:

CKEDITOR.instances['editor1'].setData(t); // where editor1 is id

或者试试这个

edt.setData(t);
于 2013-05-27T21:42:32.570 回答
1
<script>
     function SetContents(value ) {

        var oEditor =  CKEDITOR.instances.MainContent_editor1;       
        var t = document.getElementById('<%=editor1.ClientID %>').value ;
        oEditor.setData(t); 

     } 

 </script>


<script type="text/javascript">

                var ckEditor = CKEDITOR.replace('<%=editor1.ClientID %>', {

                    //               extraPlugins: 'bbcode',
                    //               fullPage : true,
                    extraPlugins: 'docprops',
                    removeDialogTabs: 'image:advanced',
                    filebrowserImageUploadUrl: 'Upload.ashx',
                    resize_enabled: false,


                    toolbar: [

                ['Source', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],

                ['FontSize', 'TextColor', 'BGColor'],

                ['Image']

            ]

                });
                var oEditor = CKEDITOR.instances.MainContent_editor1;
                var t = document.getElementById('<%=editor1.ClientID %>').value;
                oEditor.setData(t);

                function pageLoad() { // this is because after postback jquery not working

                            var instance = CKEDITOR.instances['<%=editor1.ClientID %>'];


                    if (instance) {
                        CKEDITOR.remove(ckEditor);
                    }
                    CKEDITOR.replace('<%=editor1.ClientID %>', {

                        //               extraPlugins: 'bbcode',
                        //               fullPage : true,
                        extraPlugins: 'docprops',
                        removeDialogTabs: 'image:advanced',
                        filebrowserImageUploadUrl: 'Upload.ashx',
                        resize_enabled: false,
                        toolbar: [

                ['Source', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],

                ['FontSize', 'TextColor', 'BGColor'],

                ['Image']

            ]

                    });

                    var oEditor = CKEDITOR.instances.MainContent_editor1;
                    var t = document.getElementById('<%=editor1.ClientID %>').value;
                    oEditor.setData(t);

                    }

 </script>
于 2014-10-30T04:29:12.387 回答
0

this post is quote old but I hope I am not too late for others to see this:

You forgot to enclose the server side code with quotes:

var t = "<%=editortext.InnerText %>";

the page will be rendered like this:

var t = "your text here";

instead of

var t = your text here;

using your code will definitely break javascript's parser

于 2013-09-24T09:56:18.920 回答
0

首先检查浏览器的控制台是否有错误。还要观察从您的后端代码呈现到此模板中的内容。您最有可能缺少的是引号""和/或您呈现的字符串包含未转义的撇号/引号。分数。

控制台就是一切。

于 2013-02-10T22:23:13.290 回答