<html>
<head>
<title></title>
<script>
function readTextFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var splitResponse = rawFile.responseText.split( "\n" );
for(index = 0; index < splitResponse.length; index++)
{
window.open(splitResponse[index]);
}
}
}
}
rawFile.send(null);
}
</script>
</head>
<body>
<script language="JavaScript">
readTextFile("./file.txt");
</script>
</body>
</html>
- Apr 01 Fri 2016 16:08
[JavaScript] 讀取文字檔並分割每一行
文章標籤
全站熱搜
留言列表