/*
* 生成一个十六进制形式表示的随机背景色
* 调用方法:randomBgColor()
* 参 数:无需传参,直接使用返回值
*/
function randomColor() {
// 声明一个类型为对象的变量,存放十六进制的数
var color = {
0: "0",
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7",
8: "8",
9: "9",
10: "a",
11: "b",
12: "c",
13: "d",
14: "e",
15: "f"
};
// 定义一个变量接受颜色的值
var code = "#";
// for循环6次
for (var i = 0; i < 6; i++) {
// 将每次循环获得的属性值拼接到code里面
code += color[Math.round(Math.random() * 15)];
}
// 返回十六进制颜色code
return code;
}