1

我使用带有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>&raquo; 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>
4

1 回答 1

0

我找到了解决方案。我创建了一个 servlet,并使用了 jquery。

                 $('ul').on("click","#delete",function(){                      
                 var del=$(this).parent();
                 $filename = del.text();                   
                 del.fadeOut('slow', function() { del.remove(); });
                 $.post("deleteServlet", {filename:$filename}, function() {});
             });
于 2012-05-08T02:59:24.130 回答