今天我研究了FCKEditor编辑器,发现太强大了
我用的是<iframe>来使用的
代码如下
<input type="hidden" id="txtContent" name="txtContent" value="" runat="server" />
<input type="hidden" id="txtContent___Config" value="" />
<iframe id="txtContent___Frame" src="../../editor/editor/fckeditor.html?InstanceName=txtContent&Toolbar=Default" width="100%" height="300px" frameborder="no" scrolling="no"></iframe>
但是我总是用js得不到编辑器里面的内容或者设置里面的内容,我在百度上找了好久,终于功夫不负有心人,我找到了FCKeditor
FCKeditor确实挺好用,但却缺乏一个详细的开发文档,以致于开发中遇到的很多问题,都很难从官方找到解答,只好在 网上搜索或者自己看代码,今天刚好碰到需要通过JS来读取或设置FCKeditor里面的值,通过FreeTextBox提供的API(FTB_API[ClientID].GetHTML()和FTB_API[ClinetID].SetHTML())联想和上网以及看代码,终于找到解决的方法.
以下是取值的办法
FCKeditorAPI.GetInstance(ClientID).GetXHTML(true)
以下是设值的办法
FCKeditorAPI.GetInstance(ClientID).SetHTML("字符串")
所以想要在FCKeditor中利用JS插入一段字符串可以这样做:
FCKeditorAPI.GetInstance('FCKeditor1').SetHTML(FCKeditorAPI.GetInstance(''FCKeditor1'').GetXHTML(true) + "插入的字符串")
例子:
<script language="javascript">
<!--
function checkForm(){
var Content =FCKeditorAPI.GetInstance("content").GetXHTML();
if(Content==null||Content=="")
{
alert('内容不能为空');
return(false);
form1.EditorDefault.focus();
}
return true;
}
-->
</script>