2012-03-02 5 views
0

これは私がアップロードできるファイル数の制限をしたこれまでのところ、私が持っているものハンドラ別の関数から変数の値をつかむために

//file uploader 
/////////////////////////// 
function uploader(){ 
    var file = $(this).val() 
    var error = $(this).next('.req-error') 
    var fileLimit = $(this).attr('maxlength')-1 
    var uploadedFiles = $(this).siblings('.uploaded-file').length 

    //make uploaded file label 
    if(error.length ==1){ 
     $(this).next().after('<div class="uploaded-file"><span>X</span>'+file+'</div>') 
    }else { 
     $(this).after('<div class="uploaded-file"><span>X</span>'+file+'</div>') 
    } 

    //count uploaded files 
    if(uploadedFiles >= fileLimit){ 
     $(this).attr('disabled', true) 
    }else{ 
     $(this).removeAttr('disabled') 
    } 

    //clear input field 
    $(this).val('') 
}; 
$(".input-file").change(uploader) 

function removeFile(uploader){ 
    $(this).remove() 

} 
$('.uploaded-file').live('click',removeFile) 

です。制限に達すると、入力は無効になりますが、ファイルが削除されると、その制限を下回ると再び有効になります。 Imは、uploader関数からif文を読み取るremoveFile関数を取得する方法がわかりません。

答えて

0

おそらく、アップロードされたファイルの数を表すカウンタを持つことをお勧めします。両方のあなたのアップローダー& REMOVEFILE機能と同じレベルにVARでこれを配置します。

var uploadedFiles = 0; 

function uploader() { 
    ... 
} 

function removeFile() { 
    ... 
} 

ファイルを追加/削除するよう次に/デクリメント、この変数をインクリメント。

関連する問題