我正在为学习目的构建一个文件上传器插件,并且我努力让我的回调以我想要的方式工作。简而言之,这个小部件在类型为file
的输入字段上运行。代码稍微更好地解释:如何正确触发jQuery UI自定义事件?
$.widget('ultimatum.uploadify', {
create: function() {
// Irrelevant code here
},
_onChange: function(event) {
// Private function that is fired when an "change" event
// is triggered by the input.
var files = event.target.files;
var fileInfo = {};
// When the file processing finish, I want to trigger this custom event:
this._trigger("fileready", null, fileInfo);
}
});
好吧,这样做的方式,我能处理像这样的回调:
$('#upload-files').uploadify({
fileready: function(event, file) {
// My code here
}
});
的问题是,我想处理此事件,像这样:
$('#upload-files').uploadify();
$('.upload-files').on('fileready', function(event, file) {
// My code here.
});
尽管前一种方式工作得很好,但后者并没有。使用“on”可以以这种方式处理自定义jQuery事件吗?
我看到'#'在一个选择器中,'.'在另一个选择器中。认为这是一个问题。 – Twisty