判断多个input type=file是否有已经选择好文件的代码
2012-05-23 00:00
736 查看
表单中有多个<input type="file" name="uploadfile" contentEditable="false" style="width:80%">,
提交表单时需要判断其中至少要有一个input已经选择好文件。
使用jQuery进行判断:
只要fileFlag为true,就可以退出each循环,不需要再对剩下的input进行判断。
在each中使用return false退出循环,使用return true结束当前次循环,进行下一次循环。
提交表单时需要判断其中至少要有一个input已经选择好文件。
<input type="file" name="uploadfile" contentEditable="false" style="width:80%"><br> <input type="file" name="uploadfile" contentEditable="false" style="width:80%"><br> <input type="file" name="uploadfile" contentEditable="false" style="width:80%"><br> <input type="file" name="uploadfile" contentEditable="false" style="width:80%"><br> <input type="file" name="uploadfile" contentEditable="false" style="width:80%">
使用jQuery进行判断:
var fileFlag = false; $("input[name='uploadfile']").each(function(){ if($(this).val()!="") { fileflag = true; return false; } }); if(fileFlag) { alert("已有选择好文件的"); }
只要fileFlag为true,就可以退出each循环,不需要再对剩下的input进行判断。
在each中使用return false退出循环,使用return true结束当前次循环,进行下一次循环。
相关文章推荐
- 判断多个input type=file是否有已经选择好文件的代码
- 判断多个<input type="file">是否有已经选择好文件的
- PHP文件上传判断file是否己选择上传文件的方法
- PHP文件上传判断file是否己选择上传文件的方法
- 判断dll文件是否已经注册的ASP函数代码
- <input type='file'/>选择文件,通过ajax方式传递选择的文件,后端使用controller接受
- php下利用curl判断远程文件是否存在的实现代码
- 获取工程下的路径和判断一个文件是否已经被打开
- 使用WinAPI函数FindFirstFile或GetFileAttributes判断文件是否存在
- asp.net判断FileUpload选择的文件是否是图片
- 文件的15种属性 以及 判断文件是否存在GetfileAttributes
- 判断文件是否正在被使用的JS代码
- android 安装apk文件,启动android程序,判断某个程序是否安装,遍历所有已经安装额程序
- java File 判断文件是否为符号链接
- How to know is the file exist in C++ - 在C++中如何判断文件是否存在
- iOS-判断沙盒中是否已经存在文件
- java File 判断文件是否为符号链接
- Python 判断文件或目录是否存在的实例代码