求大神指导,为啥一直提醒我init未定义。
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title></title>
<script>
function init(){
setInterval("changeImg()",2000)
}
var i=1;
function changeImg(){
i++;
var img.document.getElementById("image");
img.src="imag/"+i+".jpg";
if(i==3){
i=0;
}
}
</script>
</head>
<body onload="init()">
<img src="imag/1.jpg" id="image" >
</body>
</html> <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
function init(){
setInterval("changeImg()",2000)
}
var i=1;
function changeImg(){
i++;
var img = document.getElementById("image"); // 这里把等号写成了点
img.src="imag/"+i+".jpg";
if(i==3){
i=0;
}
}
</script>
</head>
<body onload="init()">
<img src="imag/1.jpg" id="image" >
</body>
</html> isdkz 发表于 2022-4-28 00:11
谢谢大佬。
页:
[1]