Because the editor I am also a beginner, whether it is JS or PHP, are understand a little fur. Today in the study of the CKEditor editor encountered some problems, although this is only my personal problem, but I feel that I can share to other people, and perhaps also some beginners like me will encounter this problem.
OK, now let's talk about the problem.
Before contacting the CKEditor editor, the editor made the form is used <textarea> tags, such as the production of the message book, news release, etc., but because the input box <textarea> input content format is single, basically no expansion function, So the CKEditor editor is used. It is stated here that the editor is using the ckeditor3.6 version.
In the <textarea>, we use JS to determine whether the input box content is empty generally this is written:
12345678 |
<script>
function
check_form(){
if
(myform.content.value==
""
){
alert(
"请输入内容!"
);
return
false
;
}
}
</script>
|
Here is the form code:
1234 |
<
form
action
=
""
name
=
"myform"
method
=
"post"
>
<
textarea
name
=
"content"
rows
=
10
cols
=
40
>默认内容</
textarea
>
<
input
type
=
"submit"
name
=
"sub"
check_form()">
</
form
>
|
The above two-end code combination can be used to verify the input box content.
Then after using the ckeditor3.6, if JS continues to use Myform.content.value to get the contents of the input box is not effective. Later on the Internet learned that in the ckeditor3.6 version, in order to obtain the content of the editor, you need to use CKEDITOR.instances.content_name.getData (), where content_name replaced by your own Name property value, Use Ckeditor.instancesgetdata () In versions 3.0 and earlier. and the contents of the obtained editor are tagged with HTML, so be careful.
For example, the editor's last revised JS code is as follows:
12345678910 |
<script>
function
check_form(){
var
content= CKEDITOR.instances.content.getData();
if
(content==
""
||content.match(
"请在这里输入新闻内容!"
)){
xw.content.focus();
alert(
"请填写新闻内容!"
);
return
false
;
}
}
</script>
|
JS code is visible, use CKEDITOR.instances.content_name.getData () to get the contents of the editor into the variable content, and then in the if condition to determine whether the content is empty, also determine whether the following I set the default value "Please enter the news content here!" "Once the judgment has one of them it is considered that no user fills in the news content. Here is the reason to use the Content.match () method to judge instead of content== "Please enter the news content here!" "It's because the contents of the editor you get are tagged with html, so it doesn't explain."
Then look at the form code as follows (in combination with PHP):
12345 |
<form name=
"myform" action=
""
method=
"post"
>
//显示编辑器(之前要创建CKEditor对象,这里就不写了)
<?php
$ed
->editor(
"content"
,
"请在这里输入新闻内容!"
); ?>
<input type=
"submit"
name=
"sub"
check_form()">
</form>
|
Visible in the form code, the Name property value of the editor displayed is content, and the text displayed by default is "Please enter the news here!" ”
This completes the detection of whether the content of the CKEditor editor is empty.
Of course, this blog post is still a lot of imperfect places, I hope that the experts pointed out, in order to improve the future.
(go) To use JS to determine the ckeditor3.6 version of the editor content is empty method