var adImages = new Array("image/luoli/小小1.jpg",
"image/luoli/小小2.jpg",
"image/luoli/小小3.jpg",
"image/luoli/小小4.jpg",
"image/luoli/小小5.jpg",
"image/luoli/小小6.jpg",
"image/luoli/小小7.jpg",
"image/luoli/小小8.jpg",
"image/luoli/小小9.jpg",
"image/luoli/小小10.jpg",
"image/luoli/小小11.jpg",
"image/luoli/小小12.jpg",
"image/luoli/小小13.jpg",
"image/luoli/小小14.jpg",
"image/luoli/小小15.jpg",
"image/luoli/小小16.jpg",
"image/luoli/小小17.jpg",
"image/luoli/小小18.jpg",
"image/luoli/小小19.jpg",
"image/luoli/小小20.jpg",
"image/luoli/小小21.jpg",
"image/luoli/小小22.jpg",
"image/luoli/小小23.jpg");
var thisAd= 0;function rotate()
{
thisAd++;
if(thisAd==adImages.length)
{
thisAd = 0;
}
alert("image/luoli/小小"+thisAd+".jpg11111");
// document.getElementById("adBanner").src="image/luoli/小小"+thisAd+".jpg";    页面无效
document.getElementById("adBanner").setAttribute("src",adImages[thisAd-1]);  页面无效
// $("#adBanner").attr("src",adImages[thisAd-1]);                               页面有效果
        alert("image/luoli/小小"+thisAd+".jpg1111122222");
setTimeout("rotate()",1*1000);
alert(document.getElementById("adBanner").src);

}window.onlaod = rotate();PS:
问下是不是这些JS基本方法的基本方法都加载JS的通用类库么有效的jquery方法 我同事帮我搞的,加载了一个jquery的通用库。新手求解答

解决方案 »

  1.   

    window.onload = rotate();
      

  2.   

    修改了。还是一样的效果没生效的两个src就根本没运行到哪里
      

  3.   

    window.onload = rotate();
    你试试看
    window.onload = rotate;
      

  4.   


    现在我已经删除 window.onload了
    就在后面写了 rotate();现在alert打来的只有第一个断点
    后面的两个alert都没响应,说明
    脚本直接在document.getElementById这块 已经报错
      

  5.   


    这个应该是正解了。。解释器遇到()运算符时会马上执行rotate函数,此时id值为adBanner的元素还没有被加载到DOM树中。
      

  6.   

    真的  现在解决了 
    谢谢楼上的达人
    ==============
    顺便可以问下  为啥jquery没有这个问题呢?
    或者有没有这方面的参考书么?
    这些加载的东西  我真不太懂
      

  7.   

    $("#adBanner").attr("src",adImages[thisAd-1]); //这行代码真的有效吗,我看未必啊!试一下下面的代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    div.demo {
    width:100px;
    height:100px;
    background-color:red;
    }
    </style>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
    function demo() {
    alert(document.getElementById('demo')); //null
    alert($("#demo")); //object
    $("#demo").attr('class', 'demo'); //无效
    }
    window.onload = demo();
    </script>
    </head><body>
    <div id="demo"></div>
    </body>
    </html>
      

  8.   

    把你的js代码放到
    </body>上面试试
    注意那个onload你是写错的。