小编典典

随机颜色生成器

all

鉴于此功能,我想用随机颜色生成器替换 颜色。

document.overlay = GPolyline.fromEncoded({
    color: "#0000FF",
    weight: 10,
    points: encoded_points,
    zoomFactor: 32,
    levels: encoded_levels,
    numLevels: 4
});

我该怎么做?


阅读 192

收藏
2022-03-11

共1个答案

小编典典

getRandomColor()代替"#0000FF": _

function getRandomColor() {

  var letters = '0123456789ABCDEF';

  var color = '#';

  for (var i = 0; i < 6; i++) {

    color += letters[Math.floor(Math.random() * 16)];

  }

  return color;

}







function setRandomColor() {

  $("#colorpad").css("background-color", getRandomColor());

}


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="colorpad" style="width:300px;height:300px;background-color:#000">



</div>

<button onclick="setRandomColor()">Random Color</button>
2022-03-11