jquery怎么实现自动换图片?这个代码怎么改
<!DOCTYPEHTML><html><head><metacharset="ytf-8"><scripttype="text/javascript"src="./jq...
<!DOCTYPE HTML>
<html>
<head>
<meta charset="ytf-8">
<script type="text/javascript" src="./jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
setInterval(function(){
var tb = new Array(9);
tb[0]="./11.jpg";
tb[1]="./2.jpg";
tb[2]="./3.jpg";
tb[3]="./4.jpg";
tb[4]="./5.jpg";
tb[5]="./6.jpg";
tb[6]="./7.jpg";
tb[7]="./8.jpg";
tb[8]="./9.jpg";
tb[9]="./10.jpg";
for(var i=0;i<tb.length;i++){
//var a = tb[i];
alert(tb[i]);
$("img").attr("src",tb[i]);
}
},1000);
});
</script>
</head>
<body>
<img src="./1.jpg" width="300px">
</body>
</html> 展开
<html>
<head>
<meta charset="ytf-8">
<script type="text/javascript" src="./jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
setInterval(function(){
var tb = new Array(9);
tb[0]="./11.jpg";
tb[1]="./2.jpg";
tb[2]="./3.jpg";
tb[3]="./4.jpg";
tb[4]="./5.jpg";
tb[5]="./6.jpg";
tb[6]="./7.jpg";
tb[7]="./8.jpg";
tb[8]="./9.jpg";
tb[9]="./10.jpg";
for(var i=0;i<tb.length;i++){
//var a = tb[i];
alert(tb[i]);
$("img").attr("src",tb[i]);
}
},1000);
});
</script>
</head>
<body>
<img src="./1.jpg" width="300px">
</body>
</html> 展开
1个回答
展开全部
$(function() {
var tb = ["./11.jpg", "./2.jpg", "./3.jpg", "./4.jpg", "./5.jpg", "./6.jpg", "./7.jpg", "./8.jpg", "./9.jpg", "./10.jpg"];
var img = $("img");
var i = 0;
var interval = setInterval(function() {
img.attr("src", tb[i]);
i++;
i = i > tb.length - 1 ? 0 : i;
}, 1000);
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询