fckeditor常用用法

来源:互联网 发布:eia油库存最新数据 编辑:程序博客网 时间:2024/05/21 19:33

经常使用 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 代码中插入编辑器的方法,也很常用到。

 

原创粉丝点击