(go) To use JS to determine the ckeditor3.6 version of the editor content is empty method

Source: Internet
Author: User

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>    functioncheck_form(){        if(myform.content.value==""){            alert("请输入内容!");            returnfalse;        }    }</script>

Here is the form code:

1234 <formaction=""name="myform"method="post">    <textareaname="content"rows=10cols=40>默认内容</textarea>    <inputtype="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>functioncheck_form(){    varcontent= CKEDITOR.instances.content.getData();    if(content==""||content.match("请在这里输入新闻内容!")){        xw.content.focus();        alert("请填写新闻内容!");        returnfalse;    }}</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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.