请问,如何获取 FCKeditor 内容编辑框 里的文字?
不点提交的情况下 如何获取?
我在 fckeditor.html 里 <textarea id="eSourceField" dir="ltr" style="WIDTH: 100%; HEIGHT: 100%">直接加文字</textarea> 直接加文字也没显示出来
不点提交的情况下 如何获取?
我在 fckeditor.html 里 <textarea id="eSourceField" dir="ltr" style="WIDTH: 100%; HEIGHT: 100%">直接加文字</textarea> 直接加文字也没显示出来
include_once(ROOT_PATH . 'includes/fckeditor/fckeditor.php'); // 包含 html editor 类文件$input_name='content';//name值
$input_value='内容';//value
$editor = new FCKeditor($input_name);
$editor->BasePath = '../includes/fckeditor/';
$editor->ToolbarSet = 'Normal';
$editor->Width = '100%';
$editor->Height = '320';
$editor->Value = $input_value;
$FCKeditor = $editor->CreateHtml();
echo $FCKeditor;//FCKeditor页
<input type=button name=btnSubmit value="显示" onClick="showcont()">function showcont(){
var oEditor = FCKeditorAPI.GetInstance('content'); //name值
var checkContent = oEditor.GetXHTML(); //获取FCKeditor里面的内容
alert(checkContent);
}
oEditor 是什么,我的JS方法是写在 fckeditorcode_ie.js 里的
<tr id="eWysiwyg">
<td id="eWysiwygCell" height="100%" valign="top">
<iframe id="eEditorArea" name="eEditorArea" height="100%" width="100%" frameborder="no" src="fckblank.html"></iframe>
</td>
</tr>
我尝试用document.getElementById("eWysiwygCell").innerHTML= 是可以插入内容 但用 document.getElementById("eWysiwygCell").value 却是 undefined
能不能帮我看看,现在怎么获取
fckeditorcode_ie.js里面有for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ]oEditor就是FCKeditor对象
这是正确,btnSubmit 是你提交内容的按钮。//jquery button是按钮的CLASS
$(function(){
$(".button").click(function(){
var oEditor = FCKeditorAPI.GetInstance('shop_ad_content'); //name值
var checkContent = oEditor.GetXHTML(); //获取FCKeditor里面的内容
alert(checkContent);
return false;
});
});参考http://www.dnbcw.com/biancheng/net/jhzc143106.html
oFormat168Item.IconPath = FCKPlugins.Items['formatcommands'].Path + 'placeholder.gif'; //注册按钮项
FCKToolbarItems.RegisterItem('Format168', oFormat168Item); // The object used for all Format168 operations.
var FCKFormat168 = new Object(); FCKFormat168 = function(name){ this.Name = name; } //FCK_TRISTATE_ON为默认是选中状态 下面的两个方法是实现接口的两个必须的方法,否则会报脚本错误
FCKFormat168.prototype.GetState = function() { return FCK_TRISTATE_OFF; } //此方法是点击按钮后要完成的操作
FCKFormat168.prototype.Execute = function(){ FormatText(); }
//以下都是实现功能的方法
function FormatText() {
var oEditor = FCKeditorAPI.GetInstance('content') ;
var html = oEditor.EditorDocument.body.innerText;
alert(html);
} ; // Register the related command
FCKCommands.RegisterCommand('Format168', new FCKFormat168('Format168'));
测试可以
不过那个链接的方法好像有点复杂 我后来直接在 FCKConfig.ToolbarSets["Default"] = 里加了一个
然后在相应的fckeditorcode_ie.js里修改 按钮是出来了
但在这个按钮点击事件里,我就需要获取和写入内容 的办法 。。
FCK.RedirectNamedCommands=new Object();FCK.ExecuteNamedCommand=function(A,B){FCKUndo.SaveUndoStep();if (FCK.RedirectNamedCommands[A]!=null) FCK.ExecuteRedirectedNamedCommand(A,B);else{FCK.Focus();FCK.EditorDocument.execCommand(A,false,B);FCK.Events.FireEvent('OnSelectionChange');};FCKUndo.SaveUndoStep();};FCK.GetNamedCommandState=function(A){try{if (!FCK.EditorDocument.queryCommandEnabled(A)) return FCK_TRISTATE_DISABLED;else return FCK.EditorDocument.queryCommandState(A)?FCK_TRISTATE_ON:FCK_TRISTATE_OFF;}catch (e){return FCK_TRISTATE_OFF;};};FCK.GetNamedCommandValue=function(A){var B='';var C=FCK.GetNamedCommandState(A);if (C==FCK_TRISTATE_DISABLED) return null;try{B=this.EditorDocument.queryCommandValue(A);}catch(e) {};return B?B:'';};FCK.PasteFromWord=function(){FCKDialog.OpenDialog('FCKDialog_Paste',FCKLang.PasteFromWord,'dialog/fck_paste.html',400,330,'Word');};F
http://blog.csdn.net/BossDarcy/archive/2011/02/26/6210067.aspx
自己总结的,希望对你有帮助