Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将txt文件中的多个链接逐个插入到一个iframe中_Javascript - Fatal编程技术网

Javascript 将txt文件中的多个链接逐个插入到一个iframe中

Javascript 将txt文件中的多个链接逐个插入到一个iframe中,javascript,Javascript,我试图将多个src链接放入一个帧中,然后一个接一个地加载它们。以下是我目前拥有的代码: <script type="text/javascript"> $(document).ready(function(){ $('#1').on('load', function() { $('#1').attr('src', "http://www.example1.com"); }).attr('src'

我试图将多个src链接放入一个帧中,然后一个接一个地加载它们。以下是我目前拥有的代码:

<script type="text/javascript">
    $(document).ready(function(){   
    $('#1').on('load', function() {     
            $('#1').attr('src', "http://www.example1.com");             
    }).attr('src', "http://www.example2.lt");

    $('#1').on('load', function() {                 
            $('#1').attr('src', "http://www.example1.com");             
    });

    });
</script>

<iframe id="1"  width="100" height="100" src=""></iframe>

$(文档).ready(函数(){
$('#1')。在('load',function(){
$('1').attr('src',”http://www.example1.com");             
}).attr('src',”http://www.example2.lt");
$('#1')。在('load',function(){
$('1').attr('src',”http://www.example1.com");             
});
});
在这段代码中,它将首先加载example1.com url,然后加载example2.com url


我有一个存储URL的txt文件。我如何使javascript能够从txt文件中读取URL,将它们放入javascript中,然后加载iframe,每次加载的次数与txt文件中的URL相同,一个接一个?也许还有其他方法可以这样做,而不是我在这里写的方法?

我会将文件格式化为
json
编码的字符串数组,并使用
$.ajax
$.getJSON
从服务器获取它

现在已设置好阵列,您可以:

$.getJSON( ... , function(success) { 
  $('#1').on('load', function() {
    $(this).attr('src', success.pop());
  }).attr('src', 'http://www.google.com');
});
有点像这样:


但您想要实现的目标是什么?我想获得每帧的加载时间,但首先我想将所有源加载到一帧中