Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ckeditor关闭回车键_Jquery_Ckeditor - Fatal编程技术网

Jquery ckeditor关闭回车键

Jquery ckeditor关闭回车键,jquery,ckeditor,Jquery,Ckeditor,我正在尝试使用ckeditor编辑单行,因此我不希望用户能够使用enter键。有人知道如何阻止使用回车键吗 我尝试了$(“#text”).keypress(函数(事件){alert(event.keyCode);})但它没有注册。感谢您的帮助。这是一种黑客行为,但我的工作方式是更改击键配置。我将其设置为“模糊” keystrokes: [ [ 13, 'blur'], [ CKEDITOR.SHIFT + 13, 'blur' ], [ CKEDITOR.CTRL + 9

我正在尝试使用ckeditor编辑单行,因此我不希望用户能够使用enter键。有人知道如何阻止使用回车键吗


我尝试了
$(“#text”).keypress(函数(事件){alert(event.keyCode);})但它没有注册。感谢您的帮助。

这是一种黑客行为,但我的工作方式是更改击键配置。我将其设置为“模糊”

keystrokes:
   [
   [ 13, 'blur'],
   [ CKEDITOR.SHIFT + 13, 'blur' ],
   [ CKEDITOR.CTRL + 90, 'undo' ],
   [ CKEDITOR.CTRL + 89, 'redo' ],
   [ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90, 'redo' ],
   [ CKEDITOR.CTRL + 66, 'bold' ],
   [ CKEDITOR.CTRL + 73, 'italic' ],
   [ CKEDITOR.CTRL + 85 , 'underline' ],
   [ CKEDITOR.ALT + 109, 'toolbarCollapse' ]
   ]

另外,在发布数据之前,我删除了任何段落标记。

这也不是一个优雅的解决方案(正则表达式可能也太简单了,但幸运的是我不允许源代码模式)。如果您从一个键事件返回false,它就拒绝了该键,这将是一件好事

    $('#text').ckeditorGet().on('afterCommandExec', function (e) {
    var text = $('#text').ckeditorGet().getData();
    $('#text').ckeditorGet().setData(text.replace(/<\/*p>/i, ''));
    $('#text').ckeditorGet().focus();
});
$('#text').ckeditorGet().on('afterCommandExec',函数(e){
var text=$('#text').ckeditorGet().getData();
$('#text').ckeditorGet().setData(text.replace(//i',);
$('#text').ckeditorGet().focus();
});

它需要与config.shiftEnterMode组合到CKEDITOR.ENTER\p,否则您还必须处理br。焦点也不是完美的,因为它重置了光标位置。使用afterCommandExec似乎是在没有按键的情况下按下enter键后触发的事件(有关按键的类型,请参见)

以下是我所做的。我创建了一个名为“doNothing”的虚拟插件。只需在“plugins”下创建一个“doNothing”目录,然后将以下代码粘贴到plugin.js文件中

(function()
{
    var doNothingCmd =
    {
        exec : function( editor )
        {
            return;
        }
    };
    var pluginName = 'doNothing';
    CKEDITOR.plugins.add( pluginName,
    {
        init : function( editor )
        {
            editor.addCommand( pluginName, doNothingCmd );
        }
    });
})();
使用
config.extraPlugins='doNothing'将插件添加到config.js文件中,然后输入

config.keystrokes =
[
    [ 13 /*Enter*/, 'doNothing'],
    [ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ],
    [ CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ],

    [ CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' ],

    [ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ],
    [ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ],
    [ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ],

    [ CKEDITOR.CTRL + 76 /*L*/, 'link' ],

    [ CKEDITOR.CTRL + 66 /*B*/, 'bold' ],
    [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
    [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ],

    [ CKEDITOR.ALT + 109 /*-*/, 'toolbarCollapse' ]
];

瞧!现在回车键完全不起作用。您还应该能够将'doNothing'分配给任何其他要禁用的键,尽管我自己没有尝试过其他键。

您遇到的问题之一是,ckeditor将其用作编辑部分的iframe,而事件(如键事件)不会像用于普通元素那样从iframe中冒泡出来

我这样做的方式是连接到ckeditor的key事件,并取消它以进入。大概是这样的:

CKEDITOR.replace($('#myText')[0], //can't be jQuery obj
{ on: {'key': ckeditorKeyPress} }
);

function ckeditorKeyPress(event){
    switch(event.data.keyCode){
      case 13: //enter key
        event.cancel();
        event.stop();
      break;
    }
    //trigger an imitation key event here and it lets you catch the enter key
    //outside the ckeditor
}
CKEditor 4在config对象上有一个可用的属性

阻止enter和shift+enter的示例:

CKEDITOR.inline('someEditorElementId', {
    blockedKeystrokes: [13, CKEDITOR.SHIFT + 13]
});

我无法让插件或被阻止的按键动作正常工作,所以我通过捕获按键事件来处理这个问题

    $('#text').ckeditorGet().on('afterCommandExec', function (e) {
    var text = $('#text').ckeditorGet().getData();
    $('#text').ckeditorGet().setData(text.replace(/<\/*p>/i, ''));
    $('#text').ckeditorGet().focus();
});
注:受此启发


blockedKeystrokes
在ckeditor 4.7.3上对我不起作用,除非我做错了什么