我正在按照教程学习 JavaScript。简单的图像滚动脚本有效,但我的也输出大量垃圾文本,示例没有。谁能告诉我我的 JavaScript 语法有什么问题?
垃圾文本如下所示:
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sl240\slmult1\lang9\f0\fs22 \par \par \tab \par \par \par \par \tab \par \par \par }
测试.html
<!DOCTYPE html>
<head>
<script src="imgscroll.js"></script>
</head>
<body>
<img src="1.jpg" id="scroll" />
</body>
</html>
imgscroll.js
window.onload = rotate;
var images = new Array("1.jpg","2.jpg","3.jpg");
var thisImg = 0;
function rotate() {
thisImg++;
if (thisImg == images.length) {
thisImg = 0;
}
document.getElementById("scroll").src = images[thisImg];
setTimeout("rotate()", 3 * 1000);
}