【问题标题】:Cleditor - minor plugin errorCleditor - 小插件错误
【发布时间】:2012-02-10 19:43:57
【问题描述】:

我不是 Javascript 专家,所以我有点困惑,为什么这个小按钮插件能在 Cleditor 中完成它应该做的事情,但 jquery 编辑器会弹出错误警告。

代码如下:

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
  }


})(jQuery);

它是一个简单的插件,当您单击按钮时将 [VIDEO] 插入到文档中。

问题在于,由于某种原因,它在插入文本后会出现这种情况

“执行 inserthtml 命令时出错” 在插件按钮下的一个黄色小窗口中。

我确信由于缺乏 Javascript 经验,我错过了一些小东西。

提前致谢

【问题讨论】:

    标签: javascript jquery cleditor


    【解决方案1】:

    错误就在这里

    editor.execCommand(data.command, html);
    

    它应该是:

    editor.execCommand(data.command, html, null, data.button);
    

    编辑:

    很烦人,在你的函数末尾添加:

    return false;
    

    这里是jsfiddle

    最终代码

    (function($) {
    
    
      // Define the hello button
      $.cleditor.buttons.video = {
        name: "video",
        image: "video.gif",
        title: "Insert Video",
        command: "inserthtml",
        buttonClick: videoClick
      };
    
    
      // Add the button to the default controls before the bold button
      $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
        .replace("bold", "video bold");
    
    
      // Handle the hello button click event
      function videoClick(e, data) {
    
            // Get the editor
            var editor = data.editor;
    
            // Insert some html into the document
            var html = "[VIDEO]";
            editor.execCommand(data.command, html, null, data.button);
    
    
            // Hide the popup and set focus back to the editor
           // editor.focus();
           return false;
      }
    
    
    })(jQuery);
    

    【讨论】:

    • 我又添加了,但错误弹出窗口仍然给我同样的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2015-10-27
    • 2020-01-29
    • 2014-10-14
    • 2013-06-09
    • 2016-01-22
    相关资源
    最近更新 更多