fck实现htm在线编辑

前端关键的fck初始化:

var oFCKeditor = new FCKeditor("MyTextArea");
        var sBasePath = "../../../../../Resource/theme/main_classic_standard/js/control/fckeditor/"
        oFCKeditor.BasePath = sBasePath;
        oFCKeditor.Height = "100%";
        oFCKeditor.Width = "100%";

        //页面全部元素加载完成后,再替换textArea
        window.onload = function () {
            oFCKeditor.ReplaceTextarea();
        }

        //FCKeditor控件加载完毕后,在调用FCKeditorAPI
        function FCKeditor_OnComplete(oFCKeditor) {
            var oEdotor = FCKeditorAPI.GetInstance("MyTextArea");
            oEdotor.GetXHTML();
            oEdotor.SetHTML($("#TexHtm").val());
        }


后端加载初始化html内容,主要是讲初始化的html内容,加载到前端服务器隐藏控件中:

        /// <summary>
        /// 显示数据
        /// </summary>
        /// <param name="Id"></param>
        private void InitObjectInfo(string Id)
        {
            if (!string.IsNullOrEmpty(Id))
            {
                CheckTable entity = singleService.Get<CheckTable>(Id);
                try
                {
                    WebClient client = new WebClient();
                    string httpString = string.Empty;
                    httpString = client.DownloadString(Server.MapPath("~/Upfile/htm/" + entity.FileName));
                    TexHtm.Value = httpString;
                }
                catch
                {
                    JSUtil.ShowAlert(this, "操作失败!");
                    return;
                }
            }
        }


后端保存html事件:

private bool SaveRecord()
        {
            if (ValidatePage() == false) return false;//验证用户输入,用于输入合法性判断
            if (ValidateInput() == false) return false;//验证用户输入,用于业务逻辑判断
            if (ViewState["__EditMode"] == null) return false;

            string strEditMode = ViewState["__EditMode"].ToString().ToLower();
            try
            {
                if (strEditMode == "add")
                {
                    CheckStandardItem entity = UIUtil.GenInstanceFromUI<CheckStandardItem>(this);
                    entity.CreateUser = GlobalUtil.CurrentUserAccount;
                    entity.ParentStandard = singleService.Get<CheckStandard>(sId.Value);
                    singleService.Save(entity);
                    UpFileModule1.UploadAttachments();//上传附件
                }
            }
            catch
            {
                return false;
            }

            return true;
        }


示例截图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值