1.随机生成四位数验证码
```
<!!DOCTYPE >
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script>
{
var
str="abcdefghijklmnopqrstuvwxyz1234567890";
var arr=str.split("");
var result="";
for(var i=0;i<4;i++)
{
var
n=Math.floor(Math.random()*str.length);
result+=str[n];
}
document.write(result);
}
</script>
</head>
<body>
</body>
</html>
```
2.生成随机颜色值
```
<!!DOCTYPE >
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script>
function getRandomColor(){
var
r=Math.floor(Math.random()*(256+1));
var
g=Math.floor(Math.random()*(256+1));
var
b=Math.floor(Math.random()*(256+1));
var rgb="rgb("+r+","+g+","+b+")";
return rgb;
}
document.write(getRandomColor());
</script>
</head>
<body>
</body>
</html>