2015-02-12 2 views
0

Привет, можно проверить, есть ли тип входного файла в нем перед запуском функции. Мне нужно как-то отключить кнопку отправки, если пользователь не вводит файл.Требовать ввода файла для хранения файла в

<script> 

$(function() { 

var bar = $('.progress-bar'); 
var percent = $('.percent'); 
var status = $('#status'); 

$('#uploaderForm').ajaxForm({ 
beforeSend: function() { 
    status.empty(); 
    var percentVal = '0%'; 
    bar.width(percentVal) 
    percent.html(percentVal); 
    $("#progressBar").removeClass('disappear').addClass('appear'); 
    $("#submitFileUpload").addClass('disappear'); 
}, 
uploadProgress: function(event, position, total, percentComplete) { 
    var percentVal = percentComplete + '%'; 
    bar.width(percentVal) 
    percent.html(percentVal); 
    //console.log(percentVal, position, total); 
}, 

success: function() { 
    var percentVal = '100%'; 
    bar.width(percentVal) 
    percent.html(percentVal); 
}, 
complete: function() { 
$("#status").text("Great, your upload was completed successfully.").removeClass('disappear'); 
$("#progressBar").removeClass('appear').addClass('disappear'); 
setTimeout(function() { 
window.location.href = "/thanks"; 
}, 2000); 
}, 

}); 

})(); 


    </script> 

ответ

1

Один из способов я могу думать о том, чтобы связать функцию на изменении входного значения и установить флаг

var flag = false; 
$('#uploaderForm input[type="file"]').bind('change', function(event){ 
    if(event && event.target && event.target.files[0]){ 
     flag = true; 
    } 
}); 
+0

вам мой друг является спасателем жизни! Не могу поблагодарить вас. –

Смежные вопросы