Javascript gets the implementation code for the value of the ckeditor editor

  • 2020-03-29 23:48:49
  • OfStack

The CKeditor editor is an upgraded version of FCKeditor
I think for FCK, it's really good, and it loads faster
Here's how to get the value of the CKeditor editor via JS for form validation

If (CKEDITOR. Instances. Content. getData () = = "") {
Alert (" content cannot be empty!" );
Return false;
}

Content is the name of the textarea
Next time I will post the configuration of CKeditor and the upload configuration, I will only make the upload of PHP

I just had a friend say that FIREFOX can not be judged as empty, I slightly modified it
My test passed under FF. The following is the JS code
The function trim (STR) {
      Return the STR. Replace (/ (a ^ / s *) | ($)/s * / g, "");
  }// remove Spaces
  Var STR = CKEDITOR. Instances. The getData ();
    STR = STR. Replace (" < Br / >" , "");
    STR = STR. Replace (" < Br>" , "");
    STR = trim (STR);
      {if (STR = = "")
              Alert (" content cannot be empty!" );
              Return false;
      }

  Specific in the use of the combination, thanks for the friend put forward

 

/ *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

The eval() function evaluates a string and executes the JavaScript code in it. (a very important function)

Var cke_arr = CKEDITOR. Instances;
Eval (" var cke_content = CKEDITOR. Instances. "+ ta_id +". The getData ();" );


Related articles: