首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cleditor -次要插件错误

Cleditor -次要插件错误
EN

Stack Overflow用户
提问于 2012-02-10 01:09:52
回答 1查看 1.5K关注 0票数 2

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

代码如下:

代码语言:javascript
复制
(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);

这是一个简单的插件,当你点击按钮时,它会将视频插入到文档中。

问题是,由于某种原因,在插入文本后,会出现以下内容

在插件按钮下的一个黄色小窗口中显示"Error Executing the inserthtml command“。

我敢肯定,由于缺乏使用Javascript的经验,我遗漏了一些小东西。

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-10 01:44:35

错误在这里,你有

代码语言:javascript
复制
editor.execCommand(data.command, html);

它应该是:

代码语言:javascript
复制
editor.execCommand(data.command, html, null, data.button);

编辑:

非常烦人,只需在函数的末尾添加:

代码语言:javascript
复制
return false;

这就是jsfiddle

和最终代码

代码语言:javascript
复制
(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);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9215426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档