javascript脚本:
<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()" /><select onclick="document.body.style.backgroundColor=this.value"><option value="blue">蓝色</option>
<option value="red">红色</option>
<option value="green">绿色</option>
</select>