简体   繁体   English

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

[英]CKEditor getEditor() Error, How to fix it?

<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'

First of all, contenteditable="true" tag is totally invalid and obsolete in your case.首先, contenteditable="true"标签在您的情况下完全无效且已过时。 Such attribute is relevant for inline instances only and, as <textarea> is not (content)editable, you don't need it .此类属性内联实例相关,并且由于<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 id passed to CKEDITOR.replace() , ie:作为解释,您看到的错误是在没有传递给CKEDITOR.replace()id元素时产生的,即:

<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.replace is called (working async?).确保您的 DOM 有效并且<textarea>在调用CKEDITOR.replace时存在(异步工作?)。

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

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 在你想要的地方打开

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>

The problem may be in included:问题可能包含在:

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

Try to remove it.尝试将其删除。 This can solve your problem这可以解决您的问题

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以上配置适用于模态形式,但也适用于正常形式

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CKEDITOR无法正常工作,并且出现错误,无法在ckeditor.js:321读取属性“ getEditor” - CKEDITOR does not work and error appears can not read property 'getEditor' at ckeditor.js:321 ckeditor.js:347未捕获的TypeError:无法读取未定义的属性“ getEditor” - ckeditor.js:347 Uncaught TypeError: Cannot read property 'getEditor' of undefined 如何解决dataview示例中的SlickGrid错误“ getEditor(columnDef)不是构造函数” - How to solve SlickGrid bug in dataview example “getEditor(columnDef) is not a constructor” 如何在react-CKEditor组件中固定图像的宽度和高度? - How to fix width and height of the image in the react-CKEditor component? Ckeditor-为什么我的代码两次触发? 以及如何解决? - Ckeditor - why does my code fire twice? And how to fix it? Ckeditor-为什么dataProcessor.htmlFilter.addRules不起作用? 如何解决? - Ckeditor - why dataProcessor.htmlFilter.addRules does not work? How to fix it? 如何修复Bootstrap 3 Modal + CKEditor 4.4空对话框 - How to fix Bootstrap 3 Modal + CKEditor 4.4 empty dialogs 如果我通过Ext.form.field.Date的getEditor收到了值,如何以正确的格式保存值? - How to save value in correct format if I received it by getEditor from Ext.form.field.Date? 如何解决IE 11中CKEditor的JavaScript错误 - How to resolve the javascript error of CKEditor in IE 11 如何解决这个错误? 未定义 - How to fix this error? Undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM