다음 코드를 사용하여 사용자가 텍스트 파일을 선택한 다음 내용을 아래 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>
예를 들어 사용자가 텍스트 파일을 선택합니다 (한 번). 그런 다음 코드는 루프를 반복하여 내용을 다시 읽고 텍스트 파일에 적용된 모든 변경 사항으로 PRE 태그를 업데이트합니다.
로컬로 작업 중이므로 어떤 서버 스크립팅도 불가능합니다.
솔루션에 SETINTERVAL이 (가) 포함될 수 있다는 느낌이 들었습니까?
감사합니다.
setInterval을 사용하지 않는 이유는 무엇입니까? –
작동시킬 수 있습니까? – jmcall10
변경된 경우 업데이트 된 내용을 얻기 위해 업로드 된 파일의 내용을 10 초마다 다시 읽으려고합니까? –