---
title: "xajax如何获取fckeditor的值"
author: "txf2004"
date: "2009-05-19T08:22:00Z"
tags: []
slug: "xajax-fckeditor"
draft: false
lastmod: "2009-09-18T21:23:52Z"
id: 471212
url: "https://txf2004.iteye.com/blog/471212"
---

xajax向html页面输出fckeditor是容易的，但是xajax如何获取fckeditor的值？在xajax的wiki上说了，但还是不明白，测试不成功，最后在fckeditor 2.4.3的\_samples/html/sample08.html中找到了答案

function GetContents()

{

// Get the editor instance that we want to interact with.

var oEditor = FCKeditorAPI.GetInstance('content1') ;

// Get the editor contents in XHTML.

//alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted.

var a = oEditor.GetXHTML( true );

xajax\_show(a);

}

function GetInnerHTML()

{

// Get the editor instance that we want to interact with.

var oEditor = FCKeditorAPI.GetInstance('content1') ;

alert( oEditor.EditorDocument.body.innerHTML ) ;

}  
&lt;?php

require\_once('./xajax/xajax.inc.php');

$xajax = new xajax();

$xajax-&gt;registerFunction('show');

$xajax-&gt;registerFunction('load');

$xajax-&gt;processRequest();

echo $xajax-&gt;getJavascript('./xajax');

//显示编辑器

function show($form) {

$obj = new xajaxResponse();

$obj-&gt;alert($form);

return $obj;

}

//根据内容载入编辑器

function load() {

require\_once('../../includes/fckeditor/fckeditor.php');

$editor = new fckeditor('content1');

$editor-&gt;BasePath = '../../includes/fckeditor/';

$editor-&gt;Value = "test";

$content = $editor-&gt;createhtml();

$obj = new xajaxResponse();

$obj-&gt;assign('content','innerHTML',$content);

return $obj;

}

?&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

&lt;head&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

&lt;link rel="icon" href="/favicon.ico" type="image/x-icon" /&gt;

&lt;link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /&gt;

&lt;title&gt;&lt;/title&gt;

&lt;meta name="Description" content="" /&gt;

&lt;meta content="" name="Keywords" /&gt;

&lt;link rel="stylesheet" rev="stylesheet" href="" type="text/css" media="all" /&gt;

&lt;script language="javascript"&gt;

&lt;!--

function GetContents()

{

// Get the editor instance that we want to interact with.

var oEditor = FCKeditorAPI.GetInstance('content1') ;

// Get the editor contents in XHTML.

//alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted.

var a = oEditor.GetXHTML( true );

xajax\_show(a);

}

function GetInnerHTML()

{

// Get the editor instance that we want to interact with.

var oEditor = FCKeditorAPI.GetInstance('content1') ;

alert( oEditor.EditorDocument.body.innerHTML ) ;

}

//--&gt;

&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;script language="javascript"&gt;

&lt;!--

xajax\_load();

//--&gt;

&lt;/script&gt;

&lt;form action="" method="post" name="f1" id="f1"&gt;

&lt;a href="#" onclick="xajax\_load();return false;" title=""&gt;载入编辑器&lt;/a&gt;

&lt;a href="#" onclick="setTimeout(xajax\_show(xajax.getFormValues('f1')),1500);" title="#"&gt;获取输入框的值&lt;/a&gt;

&lt;a href="#" onclick="GetContents();" title=""&gt;获取方式2&lt;/a&gt;

&lt;div id="content"&gt;

&lt;/div&gt;

&lt;/form&gt;

&lt;/body&gt;

&lt;/html&gt;

[http://www.corange.cn/archives/2008/10/2081.html](http://www.corange.cn/archives/2008/10/2081.html)