如何在CKEditor中将onClick侦听器添加到fileButton?

时间:2010-06-17 07:45:35

标签: javascript javascript-events ckeditor

我正在使用图片上传器插件,并有一个像这样的按钮定义:

{
    type : 'fileButton',
    id : 'uploadButton',
    filebrowser : 'info:txtUrl',
    label : editor.lang.image.btnUpload,
    'for' : [ 'Upload', 'upload' ],
    onClick : function() {alert('hey')}
}

我已经尝试将函数定义为在其他地方作为命名函数调用,没有运气。我也无法将onClick侦听器添加到其他元素,但buttonDefinition类here明确表示您应该能够向按钮添加一个。

2 个答案:

答案 0 :(得分:3)

你试过了吗?

document.getElementById('uploadButton').onclick = function() {
    alert('Hey!');
}

答案 1 :(得分:0)

这是javascript中的FileButton类

function FileButton(){
   this.type = 'fileButton';
   this.id ='uploadButton';
   this.filebrowser = 'info:txtUrl';
   this.label = "editor.lang.image.btnUpload";
   this.forr = [ 'Upload', 'upload' ];
}

FileButton.prototype.onClick = function() {alert('hey')}

或者,如果您有json对象并想要包装到javascript类对象中,请定义FileButton类并使用jquery:

function FileButton(){
   this.type = 'fileButton';
   this.id ='uploadButton';
   this.filebrowser = 'info:txtUrl';
   this.label = "editor.lang.image.btnUpload";
   this.forr = [ 'Upload', 'upload' ];
}

FileButton.prototype.onClick = function() {alert('hey')};

var a = $.extend(new FileButton(), {
          type : 'fileButton',
          id : 'uploadButton',
          filebrowser : 'info:txtUrl',
          label : "editor.lang.image.btnUpload",
          forr : [ 'Upload', 'upload' ],
          onClick : function() {alert('hey')}
        });

console.log(a);
a.onClick();

JsFiddle.net link

相关问题