我使用带有jsp的ajax上传。它运作良好,但我想为每个文件或至少为所有文件添加删除按钮。这是我的代码:
<script type="text/javascript">
$(function () {
var btnUpload = $('#upload');
var status = $('#status');
new AjaxUpload(btnUpload, {
action: 'uploadServlet',
name: 'uploadfile',
onSubmit: function (file, ext) {
if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
// extension is not allowed
status.text('Only JPG, PNG or GIF files are allowed');
return false;
}
status.text('Uploading...');
},
onComplete: function (file, response) {
//On completion clear the status
status.text('');
$('<li></li>').appendTo('#files').html('<img src="./uploads/' + file + '" alt="" height="40" width="40"/><br />' + file).addClass('success');
}
});
});
</script>
<div id="mainbody">
<h3>» AJAX File Upload Form Using jQuery</h3>
<!-- Upload Button, use
any id you wish-->
<div id="upload">
<span>Upload File
<span>
</div>
<span id="status"></span>
<ul id="files"></ul>
</div>