Html CKEditor getEditor() 错误,如何解决?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19089623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:57:26  来源:igfitidea点击:

CKEditor getEditor() Error, How to fix it?

javascripthtmlasp.netckeditor

提问by Bip

<textarea cols="50" id="txt" contenteditable="true" name="editor1" runat="server" rows="10"></textarea>
<script type="text/javascript" src="css-js/ckeditor.js"></script>
<script type="text/javascript">
  CKEDITOR.replace('txt', {                    
  });       
</script>

I get this err on js :

我在 js 上得到这个错误:

TypeError: Cannot call method 'getEditor'of undefined

类型错误:无法调用'getEditor'未定义的方法

回答by oleq

First of all, contenteditable="true"tag is totally invalid and obsolete in your case. Such attribute is relevant for inline instances onlyand, as <textarea>is not (content)editable, you don't need it.

首先,contenteditable="true"标签在您的情况下完全无效且已过时。此类属性内联实例相关,由于<textarea>(内容) 不可编辑,因此您不需要它

Anyway, (even if buggy) your code works for me like a charm (fiddle). As a word of explanation, the error you see is produced when there's no element of an idpassed to CKEDITOR.replace(), i.e:

无论如何,(即使有问题)你的代码对我来说就像一个魅力(小提琴)。作为解释的话,您看到的错误是在没有id传递给 的元素时产生的CKEDITOR.replace(),即:

<textarea id="foo"></textarea>
<script type="text/javascript">
     CKEDITOR.replace( 'bar' ); // <textarea> is #foo, error will be thrown
</script>

Make sure your DOM is valid and <textarea>exist when CKEDITOR.replaceis called (working async?).

确保您的 DOM 有效并且<textarea>CKEDITOR.replace被调用时存在(异步工作?)。

回答by jayadevkv

Use

CKEDITOR.appendTo( 'txt' ); for DOM elements

CKEDITOR.replace( 'textarea' ); for textarea

Ok dude try this also

好的,伙计,也试试这个

the functions appendTo and replace are all located in themedui.js file

appendTo 和 replace 函数都位于 themedui.js 文件中

try adding it separately,here is the link

尝试单独添加它,这是链接

http://docs.ckeditor.com/source/ckeditor.html#CKEDITOR

http://docs.ckeditor.com/source/ckeditor.html#CKEDITOR

回答by Sanjay

if you just want to get rid of that, use

如果你只是想摆脱它,请使用

try{CKEDITOR.replace('body')}catch{}

it will cause CKEDITOR to open where you want it to

它会导致 CKEDITOR 在你想要的地方打开

回答by MJCoder

I had a similar problem and sorted it by doing the following;

我遇到了类似的问题,并通过执行以下操作对其进行了排序;

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
    if($("textarea").length > 0){
        CKEDITOR.replace( 'ckeditor' );
    }
</script>

回答by Nishant Singh

This is the correct way to do it(I found this method by inspecting django admin )

这是正确的方法(我通过检查 django admin 找到了这个方法)

var textAreaEl = document.getElementById("id_html_txt")
var textAreadData = textAreaEl.dataset.config

var textEditor = CKEDITOR.replace(textAreaEl, textAreadData);
textEditor.insertHtml(textAreaEl)
  • Above configuration is for modal form but will work for normal form as well
  • 以上配置适用于模态形式,但也适用于正常形式

回答by John Mark

for vanilla js

对于香草js

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
   if(document.getElementsByTagName('textarea').length > 0){
      CKEDITOR.replace( 'article-ckeditor' ); 
   }
</script>

回答by Ismoilov Amir

The problem may be in included:

问题可能包含在:

<script src="{{ asset('js/app.js') }}" defer></script>

Try to remove it. This can solve your problem

尝试将其删除。这可以解决您的问题