Javascript验证允许多个文件上传的字段。检查是否有选择? [英] Javascript validate a field that allows for multiple file upload. Check if a selection has been made?
问题描述
< input name =uploadedfile []type = filemultiple =true/>
现在,我想验证它使用JavaScript来检查文件是否被选中。我尝试了以下,但没有成功
$ p $ if(form.uploadedfile.length< 1)
{
警报(您忘记选择图像);
返回false;
}
我知道它是一个数组,但我也试过了
if(form.uploadedfile.value =='')
{
alert(您忘记选择图片) ;
返回false;
}
有人可以帮我解决这个问题。
谢谢
在 还没有找到任何关于文件属性的信息。 I have a form that allows for multiple file uploads. Now, I want to validate it using javascript to check if a file was selected. I tried the following but failed and I know its an array but i also tried can someone help me out on this one.
Thanks In this example they use a files property of the input, and check the length of that, something like this. And the JS: Haven't been able to find any info about the files-property yet. 这篇关于Javascript验证允许多个文件上传的字段。检查是否有选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
< input name =uploadedfile []id =uploadfiletype =filemultiple =true/>
和JS:
if(document.getElementById(uploadfile)。files.length <1)
{
alert(您忘记选择图片);
返回false;
}
<input name="uploadedfile[]" type="file" multiple="true"/>
if(form.uploadedfile.length < 1)
{
alert("You Forgot to select an image");
return false;
}
if(form.uploadedfile.value == '')
{
alert("You Forgot to select an image");
return false;
}
<input name="uploadedfile[]" id="uploadfile" type="file" multiple="true"/>
if(document.getElementById("uploadfile").files.length < 1)
{
alert("You Forgot to select an image");
return false;
}