输入[type = file]验证 [英] input[type=file] validation
本文介绍了输入[type = file]验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查输入文件是否为空?
我试过了:
($#$ image $ file')。 ('选择文件!');
返回false;
}
});
但没有用。
点击事件被触发之前设置了该值。而是在
change
事件中检查它。 $('#image-文件')。change(function(){
// ...
});
或者,在提交表单时更好,因为
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ submit(function(){
// ...
});
how can I check if the input file is not empty?
I tried:
$('#image-file').click(function() {
if ( ! $('#image-file').val() ) {
alert('Chose a file!');
return false;
}
});
but it didn't work.
解决方案
The click
event is fired before the value is been set. Rather check it during change
event.
$('#image-file').change(function() {
// ...
});
Or, better, during submitting of the form, because the change
won't be fired when the user selected nothing and the field itself was already empty.
$('#form').submit(function() {
// ...
});
这篇关于输入[type = file]验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文