<title>Ads</title>
<script type="text/javascript" src="js/CSP.js">
</script>
</head>
<body>
<div id="imagesDiv">
<img src="images/cvb1.gif" alt="Image Ads" id="oneImage"/>
</div>
</body>
</html>
/---- code javascript--/
var theImage = document.getElementById("oneImage");
changeAds();
var intNumber = 0;
var arrayOfImages = ["images/cvb1,gif","images/cvb2,gif","images/cvb3,gif"];
// starting function ads
function changeAds(intNumber){
theImage.setAttribute("src",arrayOfImages[intNumber]);
intNumber ++;
if (intNumber==arrayOfImages.length){
intNumber=0;
}
}
setInterval(changeAds(),2000);
我做错了什么?,我甚至试图使用window.onload = function() {changeAds(intNumber)};
,但这甚至没有用。
我收到错误
&#34; theImage.setAttribute(&#34; SRC&#34;,arrayOfImages [intNumber]); &#34;未定义。
答案 0 :(得分:1)
您的帖子上有一些我无法理解的内容。所以我做了一个演示来实现你的追随。它运作良好。
This is JSFiddle.
这是我的函数window.onload = function (){}
包含的javascript。请多加注意intNumber
。
var theImage = document.getElementById("oneImage");
changeAds();
var intNumber = 0;
function changeAds() {
var arrayOfImages = [
"http://img2.zol.com.cn/product/91/15/ces2fuhxjcejw.jpg", "http://img2.zol.com.cn/product/91/19/ce6ND3v9hwMpY.jpg",
"http://img2.zol.com.cn/product/91/18/ce2Ta7Kez9P.jpg"];
// starting function ads
theImage.src = arrayOfImages[intNumber];
intNumber++;
if (intNumber == arrayOfImages.length) {
intNumber = 0;
}
}
setInterval(changeAds, 1000);
答案 1 :(得分:0)
intNumber
。var theImage,
intNumber = 0,
arrayOfImages = ["images/cvb1,gif","images/cvb2,gif","images/cvb3,gif"];
window.onload=function() {
theImage = document.getElementById("oneImage");
setInterval(changeAds,2000);
}
// starting function ads
function changeAds(){
theImage.setAttribute("src",arrayOfImages[intNumber]);
intNumber ++;
if (intNumber==arrayOfImages.length){
intNumber=0;
}
}