HTML多个文件

时间:2017-04-26 05:13:49

标签: javascript jquery html

HTML代码:

FAILED: ParseException line 7:11 cannot recognize input near ':' 'array' '<' in column type </b>

jQuery代码:

<input type="file" name="img1" id="img1" required>
<input type="file" name="img2" id="img2">
<input type="file" name="img3" id="img3">
<input type="file" name="img4" id="img4">

我想在用户点击提交按钮时阅读多个文件。但它不起作用。我该如何解决这个错误?请帮我。

2 个答案:

答案 0 :(得分:0)

使用Jquery和each()方法我建议:

var checkValue;
var valueArray=[];
$('#button').on('click',function(){
  $('input').each(function(){    
    checkValue=$(this).val();
    if(checkValue===''){
      return;
    }
    valueArray.push(checkValue);    
  });  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" name="img1" id="img1" required>
<input type="file" name="img2" id="img2">
<input type="file" name="img3" id="img3">
<input type="file" name="img4" id="img4">
  <button id="button">Click Me</button>

答案 1 :(得分:0)

click个事件附加到<input type="submit">,致电event.preventDefault()以阻止<form>提交,使用.each()来迭代<input type="file">元素,通过{{ 1}}到this.files[0]功能。

readfile FileReader处理程序中进行调整,以便不会覆盖load处的相同密钥。

如果localStorageFileReader对象未作为参数传递给Blob,则

File会引发错误,例如.readAsDataURL() , if fileread is clicked and is called in loop and one of。文件elements文件property doe not contain文件列表object in。文件. Check if element。长度为{{1} {0 {1}} FILEREAD has。files [0] greater than`element。

before calling

plnkr http://plnkr.co/edit/1Sec8uWlK2pbXMTlfpCj?p=preview