html head script type text javascript function changeButtonColor var c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<html>
<head>
<script type="text/javascript">
function changeButtonColor(){
var colors = ["red", "green", "blue"];
var curcolor = document.d1.f1.style.color;
var i = colors.indexOf(curcolor);
var newcolor = colors[i == -1? 0: i == colors.length - 1? 0: i + 1];
document.d1.f1.style.color = newcolor;
}
</script>
</head>
<body>
<form name="d1">
<input type="button" name="f1" value="click" onClick="changeButtonColor();" />
</form>
</body>
</html>