为什么键控功能在 CKEDITOR 中不起作用?



在我的应用程序中,我有一个文本区域,我正在使用ck编辑器处理它。我正在尝试在 ck 编辑器上调用 keyup 函数,并在是否有输入的情况下将文本打印到控制台。但是它没有按我的预期工作,我无法找到错误,因为它至少没有将任何错误打印到控制台。另外,我只想将文本从ck编辑器(空格除外(获取到变量editorInput。我在这里粘贴我的代码,请有人查看并纠正我的错误并修改它以仅获取文本。提前谢谢。

CK编辑器

<div class="form-group {{ $errors->has('template_content') ? 'has-error' : '' }}">
{{ Form::label('template_content', 'Template Content') }}
{{ Form::textarea('template_content', null, array('class' => 'form-control', 'id' => 'ckeditor', 
'name' => 'ckeditor', 'required', 'data-error="Template content is required"')) }}
{!! $errors->first('template_content', '<span class="help-block">:message</span>') !!}
<div class="help-block with-errors"></div>
</div>

键控功能

$(document).ready(function () {
CKEDITOR.instances.ckeditor.on('key', function() {
var editorInput = CKEDITOR.instances["ckeditor"].getData();
if(editorInput == '') {
console.log('no-content');
} 
else {
console.log('has-content');
}
});
});

这里有一个只有js的例子。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CKEditor</title>
<script src="https://cdn.ckeditor.com/4.13.1/standard/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1"></textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
</body>
</html>

最新更新