我正在尝试将填充在函数中的数组返回到另一个数组,因此我可以将数组中的值用于幻灯片放映。
我的代码是:
var flag = 0
var slideimages = new Array()
slideimages = readfile()
function readfile(){
//read data into array x
flag =1
return x
}
if(flag == 1){
//execute slideshow functions
}
//slideshow functions definitions (for timeout n picture index etc)
//using slideimages[index] to choose pic
有人可以帮我吗?
我的幻灯片没有运行,我猜这是因为这些值没有被复制到 slideimages[]
编辑:
这是我的代码:
<html><head></head><body>
<div id="col1">
<img id="img_frame" class="lazy-img" name="slide1">
</div>
<div id="col2">
<img id="img_frame" class="lazy-img" name="slide2">
</div>
<div id="col3">
<img id="img_frame" class="lazy-img" name="slide3">
</div>
<div id="col4">
<img id="img_frame" class="lazy-img" name="slide4">
</div>
<div id="col5">
<img id="img_frame" class="lazy-img" name="slide5">
</div>
<script language="JavaScript1.1">
function getImages() {
var slideimages = new Array();
slideimages = readfile();
if(slideimages){
slideit1()
slideit2()
slideit3()
slideit4()
slideit5()
}
}
function readfile(){
var allText =[];
var Lines = [];
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "urls.txt", true);
allText = txtFile.responseText;
txtFile.onreadystatechange = function()
{
if (txtFile.readyState == 4 && txtFile.status == 200)
{// Makes sure it's found the file.
allText = txtFile.responseText;
Lines = allText.split(/\r\n|\n/);
}
else {
//alert("Didn't work");
}
}
txtFile.send(null)
return Lines
}
var slideshowspeed1=3000
var slideshowspeed2=27000
var slideshowspeed3=70000
var slideshowspeed4=11000
var slideshowspeed5=50000
var whichimage1=0
var whichimage2=100
var whichimage3=300
var whichimage4=500
var whichimage5=700
function slideit1(){
if (!document.images)
return
document.images.slide1.src=slideimages[whichimage1]
if (whichimage1<slideimages.length-1)
whichimage1++
else
whichimage1=0
setTimeout("slideit1()",slideshowspeed1)}//slideit1()
function slideit2(){
if (!document.images)
return
document.images.slide2.src=slideimages[whichimage2]
if (whichimage2<slideimages.length-1)
whichimage2++
else
whichimage2=0
setTimeout("slideit2()",slideshowspeed2)}//slideit2()
function slideit3(){
if (!document.images)
return
document.images.slide3.src=slideimages[whichimage3]
if (whichimage3<slideimages.length-1)
whichimage3++
else
whichimage3=0
setTimeout("slideit3()",slideshowspeed3)}//slideit3()
function slideit4(){
if (!document.images)
return
document.images.slide4.src=slideimages[whichimage4]
if (whichimage4<slideimages.length-1)
whichimage4++
else
whichimage4=0
setTimeout("slideit4()",slideshowspeed4)}//slideit4()
function slideit5(){
if (!document.images)
return
document.images.slide5.src=slideimages[whichimage5]
if (whichimage5<slideimages.length-1)
whichimage5++
else
whichimage5=0
setTimeout("slideit5()",slideshowspeed5)}//slideit5()
</script>
</body>
</html>
我真的不知道为什么我网页上的 div 不显示图像(其 url 在 urls.txt 文件中)。我对此真的很陌生。