簡體   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