經常使用 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 代碼中插入編輯器的方法,也很常用到。