参考网址:https://www.layui.com/doc/modules/layedit.html
layui.use('layedit', function(){
var layedit = layui.layedit;
layedit.build('demo'); //建立编辑器
});
实际应用中实例展示
layui.use(['jqform', 'laytpl', 'layer', 'jquery', 'form', 'layedit', 'jqajax'], function () {
var tpl = layui.laytpl,
$ = layui.jquery,
form = layui.form,
layer = layui.layer,
layedit = layui.layedit,
jqajax = layui.jqajax;
var index = layedit.build('content'); //建立编辑器
//获取参数
var id = getUrlParam("id");
var ajax = new jqajax();
ajax.options.method = 'POST';
ajax.options.loading = false;//使用layedit后台会报“layedit is not defined”,一直去加载,这个可以停止加载
ajax.options.contentType = "application/json;charset=UTF-8";
ajax.options.url = "/sys/callboard/getNoticeById";
ajax.options.data = {id: id};
ajax.complete = function (ret, options) {
var data = ret.data;
var informationCode = data.informationCode;
var title = data.title;
var newTitle = title+"_"+informationCode;
var content = data.content;
if (ret.httpCode == 200) {
$("#title").val(newTitle);
/*内容不可编辑。此行必须在setContent函数前修改属性,否则属性设置不成功*/
$("#LAY_layedit_1").contents().find("body[contenteditable]").prop("contenteditable",false);//jquery获取iframe里的内容
layedit.setContent(index,content);
}
};
ajax.ajax(ajax.options);
});