fckeditor编辑器的两种使用方法

需要的资源包我放我资源里了,不要积分

https://download.csdn.net/download/wybshyy/88245895

首先把FredCK.FCKeditorV2.dll添加到引用

具体方法如下,一个是客户端版本,一个是服务器端版本

客户端版本:

cs 复制代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CaseTemplate_ADD.aspx.cs" Inherits="MyProject.CaseTemplate_ADD" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>编辑</title>
    <link href="/JS/layui/css/layui.css?v=1.0" rel="stylesheet" />
    <link href="/layuiadmin/style/admin.css?v=1.0" rel="stylesheet" />
    <script src="/JS/jquery-3.4.1.js?v=1.0"></script>
    <script src="/layuiadmin/layui/layui.js?v=1.0"></script>
    <script src="/layuiadmin/lib/admin.js?v=1.0"></script>
    <script src="/JS/layui/layui.js?v=1.0"></script>
    <script src="/kfckeditor/fckeditor.js?v=1.0"></script>

</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="names" lay-verify="names" autocomplete="off" placeholder="请输入名称" class="layui-input" value="<%=strNames %>" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模板内容</label>
                        <div class="layui-input-block">
                            <script type="text/javascript">
                                var fckeditor = new FCKeditor('FCKeditor1');//新建一个fckeditor实例
                                fckeditor.BasePath = "/kfckeditor/";//设置编辑器的位置,该位置一定要以/结尾,这个basepath是指 fckeditor文件夹下所有文件的地址,默认值是这个,但是我们一般前面还要加上工程的名字,如/prj/fckeditor/这样
                                fckeditor.Create();//创建并且调用一个fckeditor编辑器
                            </script>
                        </div>
                    </div>
                </form>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn sim_btn">提交</button>
                            <input type="button" id="btnReset" class="layui-btn layui-btn-primary" value="重置" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <input type="hidden" id="hdid" value="<%=strid %>" />
    <script type="text/javascript">
        //这里一定要设置全局变量,不然下面用的时候,未定义
        var layer, form, laypage, laydate, upload, layedit, indexs01, indexs02, indexs03;
        $(function () {
            layui.use(['index', 'layer', 'form', 'laypage', 'laydate', 'upload', 'jquery', 'layedit'], function () {
                layer = layui.layer;
                form = layui.form;
                laypage = layui.laypage;
                laydate = layui.laydate;
                upload = layui.upload;
                layedit = layui.layedit;//注册layedit
                var $ = layui.jquery;

            });


            //提交表单
            $("body").on("click", ".sim_btn", function () {
                saveData();
            });


        });


        function saveData() {
            var errorMsg = "";
            var id = $("#hdid").val();
            var names = $("#names").val();//
            var contents = $("#xEditingArea").html();//
            //var oEditor = FCKeditorAPI.GetInstance('FCKeditor1');
            var oEditor = FCKeditorAPI.GetInstance("FCKeditor1");
            

            alert(oEditor.GetXHTML(true));//获取FCK编辑器里的值
            alert(FCKeditor1);
            alert(FCKeditor1___Config);
            return false;
            if (names == "") {
                errorMsg = "请输入名称";
            }
            //if (names == "") {
            //    errorMsg = "请输入姓名";FCKeditor1  FCKeditor1___Config
            //}
            if (errorMsg != "") {
                layer.msg(errorMsg, { icon: 7 });
                return false;
            }
            loadIndex = layer.load(0);
            var url = "/CaseTemplate_ADD.aspx";
            $.ajax({
                type: "POST",
                url: url,
                dataType: "JSON",
                data: { 'action': 'SaveData', 'id': id, 'typeID': typeID, 'names': names, 'links': links, 'isShow': isShow, 'orderNum': orderNum },
                success: function (result) {
                    if (result.State) {
                        layer.close(loadIndex);
                        layer.msg("操作成功", { time: 1000 });
                        setTimeout(closeRefresh, 1000);//关闭当前iframe,刷新指定iframe
                    }
                    else {
                        layer.msg(result.ErrorMsg, { time: 3000 });
                    }
                }, complete: function (result) {
                    layer.close(loadIndex);
                }
            });
        }



    </script>
</body>
</html>

服务器端

先在配置文件里配置好,再把资源包放项目里

<appSettings>

<add key="FCKeditor:BasePath" value="~/kfckeditor/"/>

<add key="FCKeditor:UserFilesPath" value="~/Files/"/>

</appSettings>

代码:

cs 复制代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test02.aspx.cs" Inherits="MyProject.Test02" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1">
        <div>0000
            <FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" Height="480px">
            </FCKeditorV2:FCKeditor>
        </div>
    </form>
</body>
</html>

取值后台用FCKeditor1.value就可以了,提交按钮必须要加runat="server"

相关推荐
浅陌sss24 分钟前
C#容器源码分析 --- Queue<T>
c#
观无2 小时前
JWT认证服务与授权 .netCore
c#
FAREWELL000752 小时前
C#核心学习(十五)面向对象--关联知识点(1)命名空间
学习·c#·命名空间
宝桥南山3 小时前
Model Context Protocol (MCP) - 尝试创建和测试一下MCP Server
microsoft·ai·微软·c#·.net·.net core
码猩4 小时前
C# winform根据EXCEL匹配文件后将txt的图片分别下载到指定的文件夹里
开发语言·c#·excel
搬砖工程师Cola4 小时前
<C#>在 C# .NET 中,使用 LoggerExtensions方法创建日志
开发语言·c#·.net
风,停下8 小时前
C#MQTT协议服务器与客户端通讯实现(客户端包含断开重连模块)
c#
martian6658 小时前
100道C#高频经典面试题带解析答案——全面C#知识点总结
开发语言·c#
_Cherry|8 小时前
unity与usb串口通信(web版)
unity·c#·游戏引擎
yagerfgcs16 小时前
【配置Visual Assistant VC助手 for Visual Studio 2017】
ide·c#·visual studio