如何禁用Ajax-upload按钮?

时间:2011-02-25 21:01:46

标签: jquery ajax-upload

我正在尝试使用此插件http://valums.com/ajax-upload/。 我添加了一个文件限制,我想禁用上传按钮(不隐藏,只是禁用)。 E.g。

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>

感谢。

1 个答案:

答案 0 :(得分:0)

    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']?>));

            });
}