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

Javascript 如何将onClick侦听器添加到CKEditor中的fileButton?,javascript,ckeditor,dom-events,Javascript,Ckeditor,Dom Events,我正在使用图像上传器插件,按钮定义如下: { type : 'fileButton', id : 'uploadButton', filebrowser : 'info:txtUrl', label : editor.lang.image.btnUpload, 'for' : [ 'Upload', 'upload' ], onClick : function() {alert('hey')} } 我曾尝试将要在别处调用的函数定义为命名函数,但运

我正在使用图像上传器插件,按钮定义如下:

{
    type : 'fileButton',
    id : 'uploadButton',
    filebrowser : 'info:txtUrl',
    label : editor.lang.image.btnUpload,
    'for' : [ 'Upload', 'upload' ],
    onClick : function() {alert('hey')}
}
我曾尝试将要在别处调用的函数定义为命名函数,但运气不佳。我还无法将
onClick
侦听器添加到其他元素,但buttonDefinition类特别指出,您应该能够将一个添加到按钮中。

您尝试过:

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

这是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

有没有运气弄明白这一点?