处理索引变量以增加数组值。我认为我的概念是正确的,但我认为在语法中有些东西使 JavaScript 无法正常工作。
<html>
<head>
<style type="text/css">
body {font-family: arial;}
</style>
<script type="text/javascript">
function ChangeIt()
{
var colors;
colors = new Array("red", "blue", "green", "yellow", "purple");
i=0;
document.body.style.backgroundColor = colors[0];
var t = setInterval(function() {
i=(i>=color.length) ? 0 : i+1;
document.body.style.backgroundColor = colors[i];
}, 3000);
}
</script>
</head>
<body>
This page begins with a red background and
changes the body background to four other colors
after three seconds.<br />
The Javascript
function is set in header section and called
from the body.
</body>
<script type="text/javascript">
ChangeIt();
</script>
</body>
</html>