JS随机产生颜色

<script>

function selectForm(lowerValue,upperValue){

    var choices=upperValue-lowerValue+1;

    return Math.floor(Math.random()*choices+lowerValue)

}

var colors=["red","green","blue","yellow","black","purple","brown"];

var color=colors[selectForm(0,colors.length-1)];

alert(color);

</script>

PS:如果不懂,可查阅《JS高程》 P136

原文地址:https://www.cnblogs.com/meiqiyuanzi/p/7477341.html