1

我有一个图片上传字段,下面的代码可以在一次上传中正常工作。然后我克隆了文件上传字段,并增加了 ID。克隆的(尚未更改的)ID 不适用于此功能,即使我在其中手动更新了 ID。如何创建一个无需重写代码即可添加就地上传(=不刷新)的输入字段的系统?我不想使用多个文件上传,因为我需要特定位置的图像,一张一张。

$(函数(){

var btnUpload=$('#upload');
var uploadstatus=$('#uploadstatus');
var files=$('#files');
var title=document.getElementById('title').value;
var step=document.getElementById('stepnumber').value;
new AjaxUpload(btnUpload, {
    action: 'uploadstep.php?title='+title+'-'+step,
    name: 'uploadstep',
    onSubmit: function(file, ext){
        if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
               uploadstatus.text('Only JPG, PNG or GIF files are allowed');
               return false;
        }
           uploadstatus.html('<img src="ajax-loader.gif" height="16" width="16">');
        },
        onComplete: function(file, response){

            uploadstatus.text('');

            files.html('');

            $('#remove').show();

            if(response==="success"){
                $('<li style="list-style: none; display: block;"></li>').appendTo('#files').html('<img src="images/'+rtitle+'-'+step+'-'+file+'" alt="" width="170"/><br />').addClass('success').attr('id', 'pic');
                $('#stepurl1').val('images/'+rtitle+'-'+step+'-'+file+'');
            } else{
                $('<li style="list-style: none; display: block;"></li>').appendTo('#files').text(file).addClass('error');
            }
        }
    });

});

$(function() {
    $('#remove').click(function() {
      $('#pic').html('')
      $('#stepurl').val('');
      $('#remove').hide();
      $('#uploadstatus').text('');
      $('#upload').val('Add Photo');
    }); 
});
4

0 回答 0