这是我上传多个文件的 jquery 代码。输入文件是动态生成的,所以我在生成这些输入文件的地方调用这个 FileUploader 函数。但我必须单击两次才能上传文件。任何想法表示赞赏。
FileUploader: function($dis) {
var fileName = '';
var $htm = $($dis.parents('div.sfFormInput').find('div.cssClassUploadFiles'));
var $ht = $($dis.parent('div.uploader'));
var extension = new RegExp($ht.attr('extension'), "i");
var upload = new AjaxUpload($('#' + $dis.attr('id') + ''), {
action: Path + "UploadHandler.ashx",
name: "myfile[]",
multiple: true,
data: {},
autoSubmit: true,
responseType: "json",
onChange: function(file, ext) {
},
onSubmit: function(file, ext) {
if ($ht.attr('almul') == "false" && $('div.cssClassUploadFiles').children('div').length > 0) {
csscody.alert('<h1>Alert Message</h1><p>You can upload only one file at a time!</p>');
return false;
}
if (ext != "exe" && extension != '') {enter code here
if (ext && extension.test(ext)) {
this.setData({
'MaxFileSize': $ht.attr('filesize')
});
} else {
csscody.alert('<h1>Alert Message</h1><p>Not a valid file!</p>');
return false;
}
}
},
onComplete: function(file, response) {
var html = '';
var filePath = Path + "/UploadedFiles + file;
if (file.split('.')[1] == "jpg" || file.split('.')[1] == "JPEG" || file.split('.')[1] == "gif" || file.split('.')[1] == "bmp" || file.split('.')[1] == "png")
html = '<div title="' + Path + "UploadedFiles + file + '" ><img height="10%" width="10%" src="' + filePath + '"/><a class="sfDeleteFile"><img src="../Modules/FormBuilder/images/closelabel.png" /></a></div>';
else
html = '<div title="' + Path + "UploadedFiles + file + '" >' + file + ' <a class="sfDeleteFile"><img src="../Modules/FormBuilder/images/closelabel.png" /></a></div>';
$htm.append(html);
}
});
}
代码有效,但唯一的问题是我必须单击两次才能上传文件。