<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
.colorBox {
300px;
height: 30px;
border: 1px solid black;
float: left;
}
.btn {
120px;
height: 28px;
float: left;
}
</style>
<script type="text/javascript">
function randomValue(v) {
var r = Math.random() * v; //生成随机[0,v]的随机数
return Math.floor(r);
}
function randomColor() { // 遇到问题, Maximum call stack size exceeded"异常。。。为什么呢
var cbox = document.getElementById("box");
var color = "rgb(" + randomColor(255) + "," + randomValue(255) + "," + randomValue(255) + ")";
cbox.style.backgroundColor = color;
cbox.innerHTML = color;
cbox.style.textAlign = "center";
}
</script>
<body>
<div class="colorBox" id="box"></div>
<input type="button" class="btn" value="生成随机颜色" onclick="randomColor()" />
</body>
</html>
。。。。。。。。。。。。。。。。。。
通过点击按钮随机生成颜色显示在框中,但是报错栈溢出????弄不明白,为什么会溢出呢?