我不是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);这是一个简单的插件,当你点击按钮时,它会将视频插入到文档中。
问题是,由于某种原因,在插入文本后,会出现以下内容
在插件按钮下的一个黄色小窗口中显示"Error Executing the inserthtml command“。
我敢肯定,由于缺乏使用Javascript的经验,我遗漏了一些小东西。
提前感谢
发布于 2012-02-10 01:44:35
错误在这里,你有
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);https://stackoverflow.com/questions/9215426
复制相似问题