-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangebgColor.html
More file actions
46 lines (44 loc) · 1.22 KB
/
changebgColor.html
File metadata and controls
46 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
</head>
<body>
请输入颜色编码:
<input id="form" type="text" name="color" />
<input type="button" value="修改颜色" onclick="change()" />
<input type="button" value="自动修改颜色" onclick="autoChangeColor()" />
<script language="javascript">
function change()
{
/*未输入颜色编码,弹出提示框*/
if(form.value=="")
alert("你喜欢的颜色是?:");
/*按照输入颜色编码修改背景颜色*/
else
{
document.bgColor=("" +form.value+"");
}
}
var r=0,g=0,b=0;
function autoChangeColor()
{
r = Math.random()*255;
g = Math.random()*255;
b = Math.random()*255;
document.bgColor=(""+ r +""+ g +""+ b +"");
setTimeout("autoChangeColor()",1000);
}
</script>
<canvas id="myCanvas" width="1024" height="768" color="blue"/>
/*对比颜色块*/
/*设置对比颜色块*/
<script type="text/javascript">
var c =document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="green";
cxt.fillRect(0,0,150,75);
</script>
</body>
</html>