我正在尝试使用 html 元素创建自己的插件和对话框。单击 html 元素时,我希望将一些文本添加到编辑器中。我找不到绕过 onOk
函数的方法。
如果我在 onOk
函数内使用 editor.insertHtml(' some code ')
,则会添加文本,但如果我想在外部使用它,我会得到 未捕获的类型错误:无法读取未定义(…)的属性“编辑器”
错误。
访问编辑器的正确方法是什么?
CKEDITOR.dialog.add( 'smiley2', function( editor ) {
return {
title: 'Abbreviation Properties',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'html',
id: '2',
label: 'Explanation',
html: "<div onclick=\"editor.insertHtml(' some code ')\">add code</a></div></div>"
}
]
}
],
onShow : function()
{
document.getElementById(this.getButton('ok').domId).style.display='none'; // disapper ok btn
},
onOk: function() {
editor.insertHtml(' abbr ');
}
};
});
最佳答案
CKEDITOR.dialog.add( 'smiley2', function( editor ) {
var onChoice = function(evt) {
var target;
target = new CKEDITOR.dom.element(evt);
editor.insertHtml("SMILEY YES!");
CKEDITOR.dialog.getCurrent().hide();
};
var onClick = CKEDITOR.tools.addFunction(onChoice);
return {
title: 'Abbreviation Properties',
minWidth: 400,
minHeight: 200,
buttons: [CKEDITOR.dialog.cancelButton],
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'html',
id: '2',
label: 'Explana22tion',
html: "<div onclick=\"CKEDITOR.tools.callFunction(" + onClick +", this); return false;\" >111111</a></div></div>"
}
]
}
]
};
});
关于javascript - 从对话框 html 元素访问 ckeditor 函数而不使用 "onOk",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120075/