0
我目前使用Valums JQuery文件上傳插件。該插件使用起來非常方便,但我不喜歡代碼的外觀。因爲它佔據內部document.ready
如:JQuery Ajax插件文件上傳簡化代碼
$(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}#);
});
感謝