[英]How can I check whether CK Editor has input using JS/jQuery?
在我的应用程序中,有一个 textarea,我使用了 CK Editor。 现在我想检查用户是否输入了一些东西(空格除外)。 有一些方法可以做到这一点。 但没有什么对我有用。 当我使用它时,它会抛出一个未定义的错误。
文本区域
<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' => 'editor1',
'name' => 'editor1', 'required', 'data-error="Template content is required"', 'id' =>
'templateContent')) }}
{!! $errors->first('template_content', '<span class="help-block">:message</span>') !!}
<div class="help-block with-errors"></div>
</div>
JS函数
var a = CKEDITOR.instances["editor1"].getData();
if (a == '') {
//code to execute
} else {
//code to execute
}
错误
未捕获的类型错误:无法读取未定义的属性“getData”
第一的
{{ Form::textarea('template_content', null, array('class' => 'form-control', 'id' => 'editor1',
'name' => 'editor1', 'required', 'data-error="Template content is required"', 'id' =>
'templateContent')) }}
这里你有两个id
,你的 textarea id 是 templateContent。 删除'id' => 'templateContent'
其次,这不是观察者!,它不会实时更新您。 例如,您需要以某种方式触发它
<button id="test">get data</button>
$(document).ready(function() {
$("#test").click(function() {
var a = CKEDITOR.instances["editor1"].getData();
console.log(a);
});
});
单击按钮并检查控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.