我有以下代碼,它允許用戶選擇一個文本文件,然後它將內容加載到下面的PRE標記中。每隔10秒重新載入一次文本文件的內容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Load text file</title>
<script type="text/javascript">
\t \t function readText(that){
\t \t \t if(that.files && that.files[0]){
\t \t \t \t var reader = new FileReader();
\t \t \t \t reader.onload = function (e) {
\t \t \t \t \t var contents = e.target.result;//.replace("\r\n","<br/>");
\t \t \t \t \t contents = contents.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
\t \t \t \t \t document.getElementById('board').innerHTML= contents;
\t \t \t \t };//end onload()
\t \t \t \t reader.readAsText(that.files[0]);
\t \t \t }//end if html5 filelist support
\t \t }
</script>
</head>
<body>
<input type="file" onchange='readText(this)' /> <hr />
<pre id="board" contenteditable = "true">
This is where the text from the chosen text file will be loaded.
</pre>
</body>
</html>
是否可以讀取所選擇的文件每10秒的內容是什麼?
例如,用戶選擇文本文件(一次)。 然後代碼循環並重新讀取內容並更新PRE標籤,並對文本文件進行任何更改。
我在本地工作,所以任何服務器腳本是不可能的。
我有一種感覺,解決方案可能涉及SETINTERVAL?
謝謝大衛。
爲什麼不只是使用setInterval? –
你能夠得到它的工作? – jmcall10
您想要每10秒重新讀取上傳文件的內容,以便在其更改的情況下獲取其更新的內容? –