首页 > Web开发 > 详细

【js】随机色的2种实现方式

时间:2017-09-19 18:52:49      阅读:285      评论:0      收藏:0      [点我收藏+]

随机颜色的二种写法

写法一:
var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "A", "B","C","D"];
function Color(){
  var str = "#";
  for(var i=0;i<6;i++){
    str += arr[Math.floor(Math.random()*arr.length)]
  }
  return str;
}

写法二:
function Color() {
  var r = Math.floor(Math.random()*256),
  g = Math.floor(Math.random()*256),
  b = Math.floor(Math.random()*256);
  return "rgb("+r+","+g+","+b+")";
}

【js】随机色的2种实现方式

原文:http://www.cnblogs.com/Mr-Welson/p/7553413.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!