<html>
<head> <title>颜色变化 </title> <script type="text/javascript">
function change(color){
if(color=="red"||color=="yellow"||color=="green")
document.bgColor=color;
}
</script>
</head>
<body bgColor="black">
<form action="" method="post">
<input type="button" name="red" value="红色" onClick="change('red')"/>
<input type="button" name="yellow" value="黄色" onClick="change('yellow')"/>
<input type="button" name="green" value="绿色" onClick="change('green')"/> </form>
</body> </html>
<head> <title>颜色变化 </title> <script type="text/javascript">
function change(color){
if(color=='red') {
document.bgColor='red';
}
else if(color=='yellow') {
document.bgColor='yellow';
}
else if(color=='green')
{
document.bgColor='green';
}
return false;
}
[code=HTML]
</script>
</head>
<body bgColor="black">
<form action="" method="post">
<input type="button" name="red" value="红色" onClick="change('red')"/>
<input type="button" name="yellow" value="黄色" onClick="change('yellow')"/>
<input type="button" name="green" value="绿色" onClick="change('green')"/> </form>
</body> </html> [/code][/code]
<html>
<head> <title>颜色变化 </title>
</head>
<body bgColor="black">
<form action="" method="post">
<input type="button" name="red" value="红色" onClick="o.bgColor='red';"/>
<input type="button" name="yellow" value="黄色" onClick="o.bgColor='yellow';"/>
<input type="button" name="green" value="绿色" onClick="o.bgColor='green';"/>
</form>
</body>
</html>
function change(color){
if(color==red)
document bgColor=red;
else if(color==yellow)
document bgColor=yellow;
else if(color==green)
document bgColor=green;
}
return false;
</script> 少单引号 那这是跟变量比了
<html>
<head> <title>颜色变化 </title>
<script type="text/javascript">
var o=document;
</script>
</head>
<body bgColor="black">
<form action="" method="post">
<input type="button" name="red" value="红色" onClick="o.bgColor='red';"/>
<input type="button" name="yellow" value="黄色" onClick="o.bgColor='yellow';"/>
<input type="button" name="green" value="绿色" onClick="o.bgColor='green';"/></form>
</body></html>