如何将javascript可编辑FileList发送到服务器?

时间:2014-11-19 12:26:14

标签: javascript jquery ajax filelist

在此documentaion中说,在Javascript中我们无法编辑'input'元素内的FileList,因为它只是readonly。那么将一些其他javascript FileList发送给服务器的替代方法是什么呢?

1 个答案:

答案 0 :(得分:0)

这是一个HTML测试页面:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>test-page</title>
 <script type="text/javascript">
//<!--

var fileobj, file;
function init()
{ fileobj=document.getElementById('filepick');
  fileobj.focus();
  fileobj.click(); //SHOULD auto-trigger the file-select popup, but doesn't
  return;
}

function filed()
{ file = fileobj.files;
  //At this point we should have an array of "item" objects,
  // containing all the files in the directory.
  //You can write code to pluck whatever you want from the array,
  // and then send that list to the server.
  return;
}

 // -->
 </script>
</head>
<body onload="init();">
<input id="filepick" type="file" multiple="multiple" onchange="filed();" /><br />
User: please click button and select all files in the relevant directory.  Thanks!
</body>
</html> 
相关问题