关闭并重新打开框后,无法访问 colorBox 中的 wysihtml5 文本区域



我有一个wysiHtml5文本区域在一个弹出窗口,通过colorbox:

$j.colorbox({
                inline: true,
                href: "#popup",
                scrolling: false,
                onLoad: function() {
                    $('#cboxClose').remove();
                },
                onCleanup: function () {
                    $j("div#popup").hide();
                },
                onClosed: function () {
                    editor = null;
                },
                onComplete: function () {
                    var editor = new wysihtml5.Editor("wysiwygText", { // id of textarea element
                        toolbar: "wysihtml5-toolbar", // id of toolbar element
                        parserRules: wysihtml5ParserRules, // defined in parser rules set 
                        stylesheets: ["Styles/wysihtml5.css", "Styles/wysihtml5.css"]
                    });

                }
            });

编辑器在颜色框第一次弹出时工作良好。但是如果它被关闭并重新打开,用户就不能点击进入编辑器。

我想知道这是否与我试图重新创建编辑器对象有关?问题是,如果我在颜色盒启动之前创建编辑器,那么当颜色盒启动时,编辑器就会"崩溃"。(例如,如果我将#popup设置为可见,我可以在页面加载时编辑它,但是当我启动颜色框时,我仍然无法编辑内容。

行为是我可以看到文本区域,但我不能"点击进入"它

这可能不会帮助你,但我有这样一个问题…我必须在元素被设置为对话框之后创建编辑器。

              $(".addtext").click(function(){
                    $("#editorcontainer").dialog({
                        width: 737
                    });
                    (function($){
                        $("#wysihtml5-textarea").wysihtml5(); 
                    })($1_7_2);
                });

唯一的问题是wysihtml5编辑器的重复与对话框的并发打开。当我修复它时,我会再次发布。

编辑:我可能应该花点时间浏览一下wysihtml5代码,以真正理解发生了什么,但我现在不能在这上面花太多时间。我注意到每次调用wysihtml5()时,编辑器都会创建dom元素。这是在制作重复的元素,所以我们的想法是使用容器元素,并在对话框打开时创建其内部内容,并在对话框关闭时销毁其内部内容。顺便说一句,我真的很讨厌程序员不记录他们的设计。

//button click event
$(".addtext").click(function(){
        $("#editorcontainer").dialog({
             width: 737,
             open: function(event, ui){
                  //create inner html
                  $(this).html("<form><textarea id="wysihtml5-textarea" 
                  placeholder="Enter your text ..." 
                  autofocus></textarea></form>");
             },
             close: function(event, ui){
                  //remove inner html
                  $(this).html("");
              }
          });
          //older version of jQuery aliased to $1_7_2
          (function($){
               //invoke the editor
               $("#wysihtml5-textarea").wysihtml5(); 
           })($1_7_2);
 });

如果您删除此函数,并且在弹出窗口关闭时不破坏编辑器实例,该怎么办?

onClosed: function () {
  editor = null;
}

你在javascript控制台有任何错误吗?

最新更新