如何禁用Ajax的上传按钮?(How to disable Ajax-upload button?)

2019-09-28 03:35发布

我想使用这个插件http://valums.com/ajax-upload/ 。 我添加了一个文件限制,我想禁用上传按钮(不隐藏,只是禁用)。 例如

if(filesNumber>=limit)
{
    //Disable the "Upload a file" button    
}

因此,如果用户将尝试上传其他文件,他应该看到,在超出限制的消息。 你可以看看这个插件和帮助我吗?

按钮是不是一个表单按钮,它是用CSS一个div。

var btnUpload=$('#<?=$filesManagerCode?>upload');
        new AjaxUpload(btnUpload, {
            action: '<?=$boxLink?>actionMode<?=LDTR?>addfile',
            name: 'uploadFile[FilePath]',
            onSubmit: function(file, ext){
                btnUpload.attr('oldContent', btnUpload.html());
                btnUpload.html('<img src="'+jsloader.src+'"/>');
            },
            onComplete: function(file, response, temp){
                btnUpload.html(btnUpload.attr('oldContent'));
                $("#<?=$filesManagerCode?>files").load('<?=$boxLink?>', setFilesLimit(<?=$params['filesLimit']?>));
            }
        });


<div id="<?=$filesManagerCode?>upload" class="uploadButton"><span>Upload file</span> <span id="<?=$filesManagerCode?>uploadLimit"></span></div>

谢谢。

Answer 1:

    var btnUpload=$('#<?=$filesManagerCode?>upload');
           if(filesNumber>=limit)
{
    //Disable the "Upload a file" button or Do nothing:
       alert("You have reached the upload limit.");
}
else
{
            new AjaxUpload(btnUpload, {
                action: '<?=$boxLink?>actionMode<?=LDTR?>addfile',
                name: 'uploadFile[FilePath]',
                onSubmit: function(file, ext){
                    btnUpload.attr('oldContent', btnUpload.html());
                    btnUpload.html('<img src="'+jsloader.src+'"/>');
                },
                onComplete: function(file, response, temp){
                    btnUpload.html(btnUpload.attr('oldContent'));
                    $("#<?=$filesManagerCode?>files").load('<?=$boxLink?>', setFilesLimit(<?=$params['filesLimit']?>));

            });
}


文章来源: How to disable Ajax-upload button?