javascript按顺序从文本文件中读取

时间:2013-03-05 07:52:45

标签: javascript

得到这个脚本,将来自txt文件的url放入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>

我的问题 - 它不是按顺序放置网址,我希望它从底部或顶部开始然后由一个按顺序放置它们。我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个

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; 
   }
 }
}