如何使用java脚本在警告框中获取文件列表 [英] how to get the file list in alert box by using java script
本文介绍了如何使用java脚本在警告框中获取文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< html >
< head >
< 输入 type = file id = fileinput / >
< script type = <跨度 class =code-keyword> text / javascript >
function readSingleFile(evt){
var reader = new FileReader();
reader.onload = function (event){
var contents = event。 target.result;
console .log( 文件内容: +内容);
};
reader.onerror = function (event){
console .error( 无法读取文件!代码 + event.target.error.code);
};
reader.readAsText(file);
< / script >
< / head >
< 正文 >
< input type =' file' accept =' text / plain' onchange =' readSingleFile(evt)' > < br < span class =code-keyword>>
< div id = output >
...
< / div >
< / body >
< / html > < / br >
解决方案
可以在这里找到读取文件的代码示例
http://www.html5rocks.com/en/tutorials/file/dndfiles/ [ ^ ]
需要一个支持相关html5方面的浏览器。
<html>
<head>
<input type="file" id="fileinput" />
<script type="text/javascript">
function readSingleFile(evt) {
var reader = new FileReader();
reader.onload = function(event) {
var contents = event.target.result;
console.log("File contents: " + contents);
};
reader.onerror = function(event) {
console.error("File could not be read! Code " + event.target.error.code);
};
reader.readAsText(file);
</script>
</head>
<body>
<input type='file' accept='text/plain' onchange='readSingleFile(evt)'><br>
<div id="output">
...
</div>
</body>
</html></br>
解决方案
Code samples for reading files can be found here
http://www.html5rocks.com/en/tutorials/file/dndfiles/[^]
Needs a browser that supports the relevant html5 aspects though.
这篇关于如何使用java脚本在警告框中获取文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文