我正在尝试在 CKEditor 中构建一个自定义插件,其中选择单选按钮列表中的元素会更改所选元素的类。示例:
选择BIG
将添加类big
、MEDIUM
=> med
和SMALL
=> sml
。
我在必须检索所选元素的值的部分被阻止。其他一切都很顺利,我在下面的代码中设法将“MYCLASS”类应用到最接近的 li
标记。
问题:如何获取 CKeditor 的 dialog
元素中所选单选按钮的值?
代码如下:
CKEDITOR.dialog.add( 'MyDialog', function ( editor ) {
function getListElement( editor, listTag ) {
var range;
try {
range = editor.getSelection().getRanges()[ 0 ];
} catch ( e ) {
return null;
}
range.shrink( CKEDITOR.SHRINK_TEXT );
return editor.elementPath( range.getCommonAncestor() ).contains( listTag, 1 );
}
return {
title: 'Size of the element',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Size of an element',
elements: [
{
type: 'radio',
id: 'bullet-size',
label: 'Size of the bullets',
items: [ [ 'BIG', 'big' ], [ 'MEDIUM', 'mdm' ],[ 'SMALL', 'sml' ] ],
style: 'color: green',
'default': 'big',
},
]
},
],
onOk: function() {
var editor = this.getParentEditor(),
element = getListElement( editor, 'ul' ),
dialog = this,
config = editor.config,
lang = editor.lang,
style = new CKEDITOR.style(config.coreStyles_alpha);
editor.attachStyleStateChange(style, function(state) {
!editor.readOnly;
});
count = element.getChildren().count();
for(k=1; k <= count; k++){
element.getChild(k-1).setAttribute('class', 'MyClass');
}
}
}
});
最佳答案
这里是获取值的方法。 onOk
函数内部:
var my_variable = this.getVazlueOf(Id_of_you_tab, id_of_the_radio_list);
关于javascript - Ckeditor 自定义插件 - 带单选按钮的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36004753/