JS点击更换网页背景颜色

JS部分


<script type="text/javascript"> // 定义可换的颜色 var colors = ["#ff0000", "#00ff00", "#0000ff", "#ffff00", "#00ffff", "#ff00ff"]; var index = 0; // 换色方法 function changeColor() { // 获取颜色代码 var color = colors[index++]; // 更改文档的背景色 document.bgColor = color; if (index == colors.length) { index = 0; } } </script>

html部分

<input type="button" value="换色" onclick="changeColor();" />

  

posted @ 2016-07-02 17:04  God丶魔多  阅读(5473)  评论(0)    收藏  举报