[英]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)
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.