本文介绍了我如何使用javascript验证图像的两个文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用javascript验证一个文件上传及其工作正常,但我如何使用此javascript进行两个文件上传。 这是代码: -i use javascript to validate one file upload and its work good but how i use this javascript for two File Upload.This is code:-$(document).ready(function () { $("form").submit(function (e) { var form = this; e.preventDefault(); //Stop the submit for now //Replace with your selector to find the file input in your form var fileInput = $(this).find("#File_ar")[0], file = fileInput.files && fileInput.files[0]; console.log(file) if (file) { var img = new Image(); img.src = window.URL.createObjectURL(file); img.onload = function () { var width = img.naturalWidth, height = img.naturalHeight; window.URL.revokeObjectURL(img.src); if (width == 1024 && height == 358) { form.submit(); } else { alert('Image must be 1024 * 158'); } }; } }); }); 这是视图中的两个输入: -and this is two input in view :-<input class="form-control" data-val="true" data-val-required="This field is required" id="File_ar" name="File_ar" type="file" value=""><input class="form-control" data-val="true" data-val-required="This field is required" id="File_en" name="File_en" type="file" value=""> 我尝试了什么: i尝试在同一个脚本中使用File_en和File_ar一起输入这样做?What I have tried:i Try to use File_en Input With File_ar in the same script, How i do this?推荐答案 这是视图中的两个输入: -and this is two input in view :-<input class="form-control" data-val="true" data-val-required="This field is required" id="File_ar" name="File_ar" type="file" value=""><input class="form-control" data-val="true" data-val-required="This field is required" id="File_en" name="File_en" type="file" value=""> 我尝试了什么: i尝试在同一个脚本中使用File_en和File_ar一起输入这样做?What I have tried:i Try to use File_en Input With File_ar in the same script, How i do this? 这篇关于我如何使用javascript验证图像的两个文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-21 01:26
查看更多