如何将javascript可编辑文件列表发送到服务器?
在本文中,我们说在Javascript中不能在“input”元素中编辑文件列表,因为它是只读的。那么,向服务器发送我可以编辑的其他javascript文件列表的替代方案是什么呢?这是一个HTML测试页面:如何将javascript可编辑文件列表发送到服务器?,javascript,jquery,ajax,filelist,Javascript,Jquery,Ajax,Filelist,在本文中,我们说在Javascript中不能在“input”元素中编辑文件列表,因为它是只读的。那么,向服务器发送我可以编辑的其他javascript文件列表的替代方案是什么呢?这是一个HTML测试页面: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>test-page</title> <script type="text/java
<!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>
您遇到了一个问题,JavaScript的安全模型阻止轻松访问文件系统。浏览器作为一个可执行的应用程序,具有这样的访问权限,但JavaScript代码不是浏览器的可执行代码——实际上,对文件系统的访问是通过HTML代码完成的,而不是JavaScript:。更糟糕的是,在我的实验中,似乎没有办法自动触发弹出窗口,在弹出窗口中选择一个文件。理论上,对象的单击功能应该做到这一点。不过,如果你可以信任用户,下面会有一种答案。谢谢大家,但我在其他方面找到了解决方案。