2012-02-09 41 views
2

我不是一个JavaScript专家,所以我有点困惑,为什么这个小按钮插件做它应该在Cleditor中,但错误警告是由jQuery编辑器弹出。Cleditor - 次要插件错误

下面是代码:

(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); 

这是当您单击按钮插入[视频]到文档中一个简单的插件。

的问题是,由于某种原因,插入文本在此之后出现

“错误执行的命令inserthtml”插件按钮下在小黄的窗口。

我相信这是因为缺乏Javascript经验而缺少的东西。

在此先感谢

回答

3

错误是在这里你有

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); 
+0

我说,早在,但错误弹出仍然给我相同的消息。 – MadScientist 2012-02-09 18:06:17