Javascript图像幻灯片在本地工作,但在托管时不能

时间:2014-04-23 14:37:22

标签: javascript jquery html css

看起来你们是我的帮助javascript。当我加载我的网页的本地副本时,我有一个完美的幻灯片。但是,当我加载托管在GoDaddy上的实际页面时,它不起作用。第一张图片显示,但只是静态的。控制台显示没有错误。再一次,非常感谢任何和所有帮助。

<div class="auto-style1" style="width: 226px; height: 179px">
    <script language="javascript" type="text/javascript"> 
        var i = 0; var path = new Array(); 

        // LIST OF IMAGES 
        path[0] = "images/image_1.png"; 
        path[1] = "images/image_2.png"; 
        path[2] = "images/image_3.png";
        path[3] = "images/image_4.png";
        path[4] = "images/image_5.png";
        path[5] = "images/image_6.png";   

        function swapImage() 
        { 
            document.slide.src = path[i]; 
            if(i < path.length - 1) i++; 
            else i = 0; 
            setTimeout("swapImage()",3000); 
        } 
        window.onload=swapImage; 
    </script>           
    <img alt="" name="slide" height="140" src="images/image_1.png" width="224" class="auto-style2" />
</div>

3 个答案:

答案 0 :(得分:0)

您需要在文件夹名称前加上&#34; /&#34;

将路径设为

path[0] = "/images/image_1.png"; 
path[1] = "/images/image_2.png"; 
path[2] = "/images/image_3.png";
path[3] = "/images/image_4.png";
path[4] = "/images/image_5.png";
path[5] = "/images/image_6.png";   

答案 1 :(得分:0)

2件事。

  1. 检查您的文件夹案例。在Unix映像中!=图像
  2. 检查文件夹权限,文件夹应该是所有人都可以访问的。

答案 2 :(得分:0)

我无法让您的代码正常运行。试试这个:

Working demo

var i = 0; var path = new Array(); 

// LIST OF IMAGES 
path[0] = "images/image_1.png"; 
path[1] = "images/image_2.png"; 
path[2] = "images/image_3.png";
path[3] = "images/image_4.png";
path[4] = "images/image_5.png";
path[5] = "images/image_6.png";   

function swapImage()
{
    var img = document.getElementById("slide");
    img.src = path[i];
    i++;

    if(i >= path.length){
        i = 0;
    } 
    setTimeout(function() { swapImage() }, 3000);
}

window.onload=swapImage();