经常使用 fckeditor 做编辑器,每次用到的时候总是找以前的代码例子。
所以就想整理总结一些常用的例子:
一, JS 调用
1. 先把脚本文件包含进来
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
2. 可以添加一个检测函数,这里比较奇怪,用 document.getElementById("content ").value 是抓取不到值的。要两次才能抓取到值,所以编辑器值的检测另外写了一个函数
<script type="text/javascript">
function submit(){
if(oEditer.GetXHTML(true) ==""){
alert(" 警告信息! ");
return false;
}
return true;
}
var oEditer;
function FCKeditor_OnComplete( editorInstance )
{
oEditer = editorInstance;
}
</script>
3. 在 form 标签里加上 submit 方法
<form action="" method="post" onSubmit="return adminSubmit()">
4. 在要用到编辑器的 textarea 标签下加上脚本,如 textarea 标签名为 content ,则 new FCKeditor("content ") 。
<textarea id="content " name="content "><{$content}></textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor("content ") ;
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.ToolbarSet = "Shop";
oFCKeditor.Width = "400";
oFCKeditor.ReplaceTextarea();
</script>
今天先到这里了,下次继续,还有 php 代码中插入编辑器的方法,也很常用到。