【发布时间】:2010-02-24 07:30:42
【问题描述】:
我目前正在使用 Valums JQuery 文件上传插件。该插件使用起来非常方便,但我不喜欢代码的外观。因为它占用了document.ready里面如:
$(document).ready(function() {
var button = $('#button1'), interval;
new AjaxUpload(button, {
action: 'http://test.com/user/uploadfile',
name: 'myfile',
onSubmit : function(file, ext){
// change button text, when user selects file
button.text('Uploading');
// If you want to allow uploading only 1 file at time,
// you can disable upload button
this.disable();
// Uploding -> Uploading. -> Uploading...
interval = window.setInterval(function(){
var text = button.text();
if (text.length < 13){
button.text(text + '.');
} else {
button.text('Uploading');
}
}, 200);
},
onComplete: function(file, response){
button.text('Upload Finished');
window.clearInterval(interval);
// enable upload button
//this.enable();
alert(response);
}
});
});
我的问题是代码可以更简化吗?这样我就可以或多或少地让代码看起来像:
$(document).ready(function() {
var button = $('#button1'), interval;
new AjaxUpload(button, {#leads to another function}#);
});
提前致谢
【问题讨论】:
标签: jquery file jquery-plugins upload