簡體   English   中英

javascript按順序從txt文件讀取

[英]javascript reading from txt file by order

得到了以下腳本,該腳本將txt文件中的網址放入i框架中,並一一加載:

<script type="text/javascript">
    $.get("imones.txt", function (data) {
        var array = data.split(/\r\n|\r|\n/);
        var beforeLoad = (new Date()).getTime();
        var loadTimes = []; 
        var beforeTimes = [];   
        $('#frame_id').on('load', function () {                                 
            beforeTimes.push(beforeLoad);
            loadTimes.push((new Date()).getTime()); 
            $('#frame_id').attr('src', array.pop()); 
            $.each(loadTimes, function (index, value) {
                var result = (value - beforeTimes[index]) / 1000; 
                if (result < 0) { 
                    result = result * (-1);
                }   
                $("#loadingtime" + index).html(result);
                beforeLoad = value;
            });
        }).attr('src', array.pop());
    });
</script>

我的問題-它沒有按順序排列網址,我希望它從底部或頂部開始,然后依次一個按順序排列。 我怎么做?

嘗試這個

var txtFile = new XMLHttpRequest();
txtFile.open("GET", "imones.txt", true);
txtFile.onreadystatechange = function() 
{
 if (txtFile.readyState === 4)   // Makes sure the document is ready to parse.
 {
  if (txtFile.status === 200)   // Makes sure it's found the file.
   {
    allText = txtFile.responseText; 
   }
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM