Javascript验证允许多个文件上传的字段。检查是否有选择? [英] Javascript validate a field that allows for multiple file upload. Check if a selection has been made?

查看:126
本文介绍了Javascript验证允许多个文件上传的字段。检查是否有选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input name =uploadedfile []type = filemultiple =true/> 

现在,我想验证它使用JavaScript来检查文件是否被选中。我尝试了以下,但没有成功

$ p $ if(form.uploadedfile.length< 1)
{
警报(您忘记选择图像);
返回false;
}

我知道它是一个数组,但我也试过了

  if(form.uploadedfile.value =='')
{
alert(您忘记选择图片) ;
返回false;
}

有人可以帮我解决这个问题。
谢谢

解决方案

 < input name =uploadedfile []id =uploadfiletype =filemultiple =true/> 



和JS:

  if(document.getElementById(uploadfile)。files.length <1)
{
alert(您忘记选择图片);
返回false;
}

还没有找到任何关于文件属性的信息。

I have a form that allows for multiple file uploads.

<input name="uploadedfile[]" type="file" multiple="true"/>

Now, I want to validate it using javascript to check if a file was selected. I tried the following but failed

if(form.uploadedfile.length < 1)
{
    alert("You Forgot to select an image");
    return false;
}

and I know its an array but i also tried

if(form.uploadedfile.value == '')
{
    alert("You Forgot to select an image");
    return false;
}

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.

<input name="uploadedfile[]" id="uploadfile" type="file" multiple="true"/>

And the JS:

if(document.getElementById("uploadfile").files.length < 1)
{
   alert("You Forgot to select an image");
   return false;
}

Haven't been able to find any info about the files-property yet.

这篇关于Javascript验证允许多个文件上传的字段。检查是否有选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆