在一个页面动态创建ueditor

469 469
Ueditor
sam
sam 2024-05-28 12:33:47

概述

在题库系统开发的过程中,需要对题干与选项使用ueditor进行动态创建 并动态切换

代码

定义配置文件

        var ueArtileContentConfig = {
            UEDITOR_HOME_URL: "@(curGlobalResPath + "/ueditor/")",
            toolbars: [
                ['fullscreen', 'undo', 'redo', 'bold', 'italic', 'underline', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'kityformula', 'preview']
            ]
        }

点击的时候动态创建

            //单击的时候,将富文本编辑器进行替换
            Jquery("body").on("click", ".inputItem", function () {

                if (Jquery("#myEditor").length > 0) {
                    var ueditorContent = UE.getEditor('myEditor').getContent();
                    UE.getEditor('myEditor').destroy();
                    Jquery("#myEditor").parent().html("").html(ueditorContent);
                }

                layer.msg("隐藏,替换ueditor");
                var htmlContent = Jquery(this).html();
                var myEditor = Jquery("<script id='myEditor' type='text/plain' style='width:1024px;height:100px;'>" + htmlContent + "<\/script>");
                Jquery(this).html("").append(myEditor);
                UE.getEditor('myEditor', ueArtileContentConfig);
                
                

            });

核心说明

1、判断当前的编辑器是否存在,如果存在,则将当前编辑器所在地方替换成编辑器内容

2、销毁当前的编辑器

3、重新创建,在创建的时候当所在区域的html赋值给ueditor

回帖
  • 消灭零回复
作者信息
相关文章