CKEDITOR使用键盘快捷键插入特殊符号
我正在做一个项目,它有一个要求是:如果用户按下一个快捷键,那么一个符号将插入文本编辑器。比如:CKEDITOR使用键盘快捷键插入特殊符号,ckeditor,Ckeditor,我正在做一个项目,它有一个要求是:如果用户按下一个快捷键,那么一个符号将插入文本编辑器。比如: if press Shift+1 then insert ✓ if press Shift+2 then insert ✗ 我已经在textarea中完成了这项工作,但我在这个项目中使用了CKEDITOR,我尝试过这样的“击键”,但没有成功: CKEDITOR.config.keystrokes = [ [ CKEDITOR.SHIFT + 76, function(){
if press Shift+1 then insert ✓
if press Shift+2 then insert ✗
我已经在textarea中完成了这项工作,但我在这个项目中使用了CKEDITOR,我尝试过这样的“击键”,但没有成功:
CKEDITOR.config.keystrokes = [
[ CKEDITOR.SHIFT + 76, function(){
console.log('sdsd');
} ]
];
谁能帮帮我吗?感谢高级版。您需要像这样使用setkystroke方法: 对于4.x,使用editor.setKeystroke:
CKEDITOR.plugins.add( 'test', {
init: function( editor ) {
editor.setKeystroke( CKEDITOR.CTRL + 81, 'bold' ); // CTRL+Q
}
} );
对于3.x:
CKEDITOR.plugins.add( 'test', {
init: function( editor ) {
editor.on( 'instanceReady', function( evt ) {
evt.removeListener();
this.keystrokeHandler.keystrokes[ CKEDITOR.CTRL + 81 ] = 'bold'; // CTRL+Q
} );
}
} );
您可以使用命令执行如下函数
CKEDITOR.plugins.add('foo',
{
init: function( editor ) {
editor.addCommand( 'sample', {
exec: function( editor ) {
alert( 'Executing a command for the editor name "' + editor.name + '"!' );
}
} );
editor.setKeystroke( CKEDITOR.CTRL + 81, 'sample' ); // CTRL+Q
}
});
或者按照您的方式,但在定义命令之后
CKEDITOR.config.keystrokes = [
[ CKEDITOR.SHIFT + 76, 'sample' ]
];
CKEDITOR.config.keystrokes的第二个值需要一个命令名,而不是一个函数
NB:因为实现正在使用插件。您还必须使用extraPlugins
configuration配置编辑器以使用插件
CKEDITOR.replace('editor', {
extraPlugins : 'foo'
});
因为您只需要将击键映射到符号。你可以使用插件
免责声明:我是插件的作者我在这里看到了这个答案。但是它没有解决我的问题,你需要使用setKeystroke()方法,它对我来说很好。我使用的是ckeditor版本4.xIs,如果我想让多个键调用同一个函数,有没有一种方法可以将按下的键传递到调用的函数中?这正是我想要的,非常感谢。如果我希望多个键调用同一个函数,有没有办法将按下的键传递到调用的函数中?@有时24您可以使用答案中提供的键来执行此操作。例如