I'm working in the image uploader plugin, and have a button definition like this:
{
type : 'fileButton',
id : 'uploadButton',
filebrowser : 'info:txtUrl',
label : editor.lang.image.btnUpload,
'for' : [ 'Upload', 'upload' ],
onClick : function() {alert('hey')}
}
I have tried defining the function to be called elsewhere as a named function, with no luck. I also haven't been able to add an onClick
listener to other elements, but the buttonDe开发者_如何学JAVAfinition class here specifically says you should be able to add one to a button.
Have you tried:
document.getElementById('uploadButton').onclick = function() {
alert('Hey!');
}
This is the class of FileButton in javascript
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')}
Or if you have json object and want to wrap into javascript class object, define FileButton class and use 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
精彩评论