2010-06-17 41 views
2

我的图片上传插件工作,并有一个按钮的定义是这样的:如何添加onClick监听器到CKEditor中的fileButton?

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

我试图定义功能在别处为命名函数调用,没有运气。我也无法将onClick监听器添加到其他元素,但是buttonDefinition类here明确指出您应该可以将其添加到按钮。

+0

每一个运气,每一个搞清楚这一点? – davemackey 2010-06-23 20:52:43

回答

3

你试过:

document.getElementById('uploadButton').onclick = function() { 
    alert('Hey!'); 
} 
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