我正在做一個驗證過程,我需要2個suggession一個是我正在做的方式是正確的?以及如何驗證文件字段?jquery如何驗證文件字段?
任何一個讓我看到正確的方法?
var validateForm = function(form){
var submit = form.find(':submit'),
elements = form.find(':input'),
status = true;
$('#contactForm').submit(function(event){
$(elements).each(function(){
var need = $(this).data('required');
if(need === 'text' && !$.trim($(this).val()).length){
$(this).css({border:'1px solid red'});
status = false;
}else{
status = true;
}
if(need === 'textarea' && !$.trim($(this).val()).length){
status = false;
}else{
status = true;
}
if(need === 'checkbox' && !$(this).prop('checked')){
status = false;
}else{
status = true;
}
if(need === 'file'){
//how to check the file elment?
}else{
status = true;
}
})
return status;
})
}
提前致謝!