<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gd2312"> <title>制作我的第一个网页</title> </head> <body> <h1>标题1</h1> <script language="javascript"> <form name="name1"method="post" action=""> <input name="submit"type="button"value="更换背景颜色"onclick="turncolour();"><!--这是插入一个按键--> </form> var arraycolour=new Array("olive","teal","red","blue","maroon","green","yellow"); <!--定义一个颜色数组--> var n=0; function turncolour() <!--函数完成颜色变换--> { if(n==(arraycolour.length-1)) n=1; n++; document.bgColor=arraycolour[n]; } </script> </body> </html>
是不是实现变色啊!你把form的写在<script></script>中了,把他放在外面就可以了!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gd2312">
<title>制作我的第一个网页</title>
</head>
<body>
<h1>标题1</h1>
<form name="name1"method="post" action="">
<input name="submit"type="button"value="更换背景颜色"onclick="turncolour();"><!--这是插入一个按键-->
</form>
<script language="javascript">
var arraycolour=new Array("olive","teal","red","blue","maroon","green","yellow"); <!--定义一个颜色数组-->
var n=0;
function turncolour() <!--函数完成颜色变换-->
{
if(n==(arraycolour.length-1)) n=1;
n++;
document.bgColor=arraycolour[n];
}
</script>
</body>
</html>
你的告诉别人要实现什么