繁体   English   中英

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

[英]How can I add an onClick listener to a fileButton in CKEditor?

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

{
    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链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM