<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
function  color(c)
{ var a=this.form.text1.value;
if(a=="red" )
{document.bgColor="red";}
else if(a="blue")
{document.bgColor="blue";}
else if(a="yellow")
{document.bgColor="yellow";}
}
</script>
</head>
<body>
<form>
<input type="text" value="请输入颜色" name="text1"  />
<input type="button" value="确定" name="button" onclick="color()"/>
</form>
</body>
</html>

解决方案 »

  1.   

    啊啊!!!原来是form没给命名,我自己解决啦!!
      

  2.   

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script language="JavaScript">
    function  color(c)
    { var a=c.form.text1.value;
    if(a=="red" )
    {document.bgColor="red";}
    else if(a=="blue")
    {document.bgColor="blue";}
    else if(a=="yellow")
    {document.bgColor="yellow";}
    }
    </script>
    </head>
    <body>
    <form>
    <input type="text" value="请输入颜色" name="text1"  />
    <input type="button" value="确定" name="button" onclick="color(this)"/>
    </form>
    </body>
    </html>