您的位置:首页 > Web前端 > HTML

fck实现htm在线编辑

2016-07-19 20:16 507 查看
前端关键的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;
}
示例截图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息