这个程序里面,最让我感觉不错的是:
- var r,g,b;
- r = decToHex(randomNumber(256)-1);
- g = decToHex(randomNumber(256)-1);
- b = decToHex(randomNumber(256)-1);
- document.bgColor = "#" + r + g + b;
这段生成颜色的代码相当的赞,很不错的算法~~~
JavaScript代码
- function randomNumber(limit){
- return Math.floor(Math.random()*limit);
- }function decToHex(dec)
- {
- var hexStr = "0123456789ABCDEF";
- var low = dec % 16;
- var high = (dec - low)/16;
- hex = "" + hexStr.charAt(high) + hexStr.charAt(low);
- return hex;
- }function randomBgColor()
- {
- var r,g,b;
- r = decToHex(randomNumber(256)-1);
- g = decToHex(randomNumber(256)-1);
- b = decToHex(randomNumber(256)-1);
- document.bgColor = "#" + r + g + b;
- }
- randomBgColor();