js前端 讀取.log日志并顯示在頁(yè)面上

之前同事讓我?guī)兔匆幌?log日志文件,功能是上傳日志文件到頁(yè)面上,再使用任一工具把日志文件顯示到頁(yè)面上。下面的代碼只是簡(jiǎn)單的一個(gè)功能demo,顯示的是自己的一個(gè)Git日志,功能完全滿足了我自己的需要。文章最后面是整個(gè)代碼,復(fù)制代碼后直接保存為.html文件就可以了

源代碼:

<!DOCTYPE html><html lang="en">

<head> <meta charset="UTF-8">

????<meta name="viewport" content="width=device-width, initial-scale=1.0">

????<meta http-equiv="X-UA-Compatible" content="ie=edge">

????<title>Document</title>

????<style> #text{ width: 1000px; height: 800px; } </style>

</head>

<body>

????<input type="file" id="file-input" />

????<div id="file-content"></div>

????<textarea id='text'> </textarea>

?</body>

<script>

????????function readSingleFile(e) {

//獲取選擇的文件對(duì)象

var file = e.target.files[0]; if (!file) { return; }

// 創(chuàng)建FileReader對(duì)象

var reader = new FileReader();

// load 回調(diào)

reader.onload = function(e) { var contents = e.target.result;

// alert(contents)

// 內(nèi)容處理

document.getElementById("text").value = contents; };

// 讀取文件

reader.readAsText(file,"utf-8"); }

// 添加監(jiān)聽(tīng)事件

var fileInput = document.getElementById("file-input"); fileInput.addEventListener("change", readSingleFile, false);

</script></html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容