Asp.net
Reference fck js and jquery. js on the page
View call
@ Html. FckText ("Content2", Model. Content2)
Backend Extension Method
Public static MvcHtmlString FckText (this System. Web. Mvc. HtmlHelper helper, string name, string val, string width = "1500", string height = "400 ")
{
If (string. IsNullOrEmpty (name ))
{
Return MvcHtmlString. Create ("the name attribute is required ");
}
Int thm = DateTime. Now. Millisecond;
String html = @"
<Script type = "" text/javascript "">
$ (Function (){
Var oFCKeditor2 "+ thm + @" = new FCKeditor ('"+ name + @"');
// Height
OFCKeditor2 "+ thm + @". Width = "+ width + @";
// Width
OFCKeditor2 "+ thm + @". Height = "+ height + @";
// Initialize the content
OFCKeditor2 "+ thm + @". value = "" write you message here! "";
OFCKeditor2 "+ thm + @". ReplaceTextarea ();
})
</Script>
<Textarea rows = "10" "cols =" 20 "" name = "+ name + @" id = "+ name + @"""> "+ val + @" </textarea>
";
Return MvcHtmlString. Create (html );
}
Common JS methods of FCK
<Script type = "text/javascript">
Function getEditorHTMLContents (EditorName ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
Return (oEditor. GetXHTML (true ));
}
// Get the text content in the editor more self Forum: http://www.52mvc.com/showtopic-1382.aspx
Function getEditorTextContents (EditorName ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
Return (oEditor. EditorDocument. body. innerText );
}
// Set the content in the editor
Function SetEditorContents (EditorName, ContentStr ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
OEditor. SetHTML (ContentStr );
}
</Script>
Principle
Basic usage
1. First, log on to the official website to download the package, for example, FCKeditor_2.6.4.1.zip.
2. decompress the package and generate a directory. fckeditor copies the directory to the root directory of the project.
3. reference the toolkit on the page. use Javascript reference here, and use the FCK tag reference.
<Script type = "text/javascript" src = "fckeditor/fckeditor. js"> </script>
4. Define a text compilation field and load the event when the form is loaded:
<Script type = "text/javascript">
Window. onload = function (){
Var oFCKeditor = new FCKeditor ('mydata ');
// Compiler basic path
OFCKeditor. BasePath = "/fckeditor /";
// Height: www.2cto.com
OFCKeditor. Width = 600;
// Width
OFCKeditor. Height = 400;
// Initialize the content
OFCKeditor. value = "write you message here! ";
OFCKeditor. ReplaceTextarea ();
}
</Script>
<Textarea rows = "10" cols = "20" name = "myData" id = "myData">
</Textarea>