本帖最后由 舒远 于 2012-11-20 12:33 编辑
为什么不用一个<p></p>,然后css控制文字的颜色改变不是省很多页面代码么?这样带宽就节省了。
小小的改写了一下:- <html>
- <head>
- <title></title>
- <script type="text/javascript" language="javascript">
- var colors = ["red","blue","green","yellow","cyan","#aabbcc"];
- var index = 0;
- //按顺序的颜色
- function flower(){
- if(index == colors.length)
- index = 0;
- document.getElementById("p1").style.color = colors[index++];
- setTimeout("flower()",1000);
- }
- //随机的颜色
- function randomIndex(){
- var index = parseInt(Math.random() * (colors.length),10);
- document.getElementById("p1").style.color = colors[index];
- setTimeout("randomIndex()",1000);
- }
- </script>
- </head>
- <body onload="randomIndex()">
- <div align="center">
- <p id="p1">黑马程序员,追求梦想永不止步</p>
- </div>
- </body>
- </html>
复制代码 |