2012-02-09 45 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