FileReader讀取檔案
阿新 • • 發佈:2019-01-29
<html lang="en">
<head>
<meta charset="UTF-8">
<title>H5 file</title>
</head>
<body>
<script>
function readfile(f){
var reader = new FileReader();
reader.readAsText(f,'GB2312');//讀取檔案
reader.onload = function(){
var text = reader.result;
text = text.replace(/[\s+,'[棉花糖小说网Mianhuatang.cc']/g, "");
text = text.replace(/['。']/g , "\n");
text = text.replace(/站頁面清爽\W{24}/g, "");
text = text.replace(/更新快\W{24}/g, "");
var out = document.getElementById("output");
out.innerHTML = "";
out.appendChild(document.createTextNode(text));
}
reader.onerror = function (e){
console.log('Error',e);
}
}
</script>
Select the file to display:
<input id="h5file" type="file" onchange = "readfile(this.files[0])">
<pre id="output"></pre><!-- 程式碼輸出 -->
</body>
</html>