zoukankan      html  css  js  c++  java
  • random 小案例

    <!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>

    。。。。。。。。。。。。。。。。。。

    通过点击按钮随机生成颜色显示在框中,但是报错栈溢出????弄不明白,为什么会溢出呢?

  • 相关阅读:
    C# String.Format格式说明
    jQuery.json.js
    禁止别人使用"另存为"保存你的网页
    组合问题的递归算法
    jQuery,contents()
    C#string,StringBuilder和Regex类的讲解
    jQuery性能优化指南
    加密算法的C#实现
    m,n组合算法
    jQuery插件—获取URL参数
  • 原文地址:https://www.cnblogs.com/wxhhts/p/7799453.html
Copyright © 2011-2022 走看看