当使用带有CKEDITOR
标签的<textarea>
时,它不起作用。
<textarea id="editor1" name="description" class="form-control" cols="10" rows="10" required></textarea>
<script>
CKEDITOR.replace('editor1');
</script>
有什么建议?
请参阅:https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-required
您需要为CKEditor分配一个事件处理程序,它“替换”本机textarea
元素。
如果您正在寻找比标准警报对话框更多的显示消息的方式,请尝试使用notifications。下面是最基本的示例(当您在空编辑器中按submit
按钮时,将显示通知):
var editor = CKEDITOR.replace( 'editor1', {
language: 'en',
extraPlugins: 'notification'
});
editor.on( 'required', function( evt ) {
editor.showNotification( 'This field is required.', 'warning' );
evt.cancel();
} );
请注意,与文档中的内容相反,notification
插件似乎包含在每个预设中。你可以使用Available Plugins
的online builder,list box搜索框来查看它。
您可以使用
<script>
function validate() {
var resultado_validacion=true;
$("#editor_error").html("");
var editor_val = CKEDITOR.instances.editor.document.getBody().getChild(0).getText().trim();
if(!(editor_val.length>0)){
$("#editor_error").html("Se requiere contenido del oficio");
resultado_validacion=false;
}
return resultado_validacion;
}
</script>
<form onSubmit="return validate();">