汇才同飞教育汇才同飞学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › zhangjiafu › 日志

将10元钱,随机分成三个红包,在页面或控制台显示三个红包的金额

2020-12-01 15:16:56 查看(23) 回复(0)

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        function f() {
            let money=document.getElementById("money").value;
             money*=100;
             money-=3;
             let r1=Math.random();
             let r2=Math.random();
             let r3=Math.random();
             let sum=r1+r2+r3;
             let m1=money*r1/sum;
             let m2=money*r2/sum;
             let m3=money*r3/sum;

             m1=Math.round(m1);
             m2=Math.round(m2);
             m3=money-m1-m2;
             m1++;
             m2++;
             m3++;
             do(m1/100,m2/100,m3/100);

        }
    </script>

</head>
<body>
<input type="text" id="money" value="10">元<br>
<input type="text" id="num" value="3">个红包<br>
<button onclick="f()">塞钱进红包</button>
<div id="result"></div>
</body>
</html>

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.cn 备案号:京ICP备17025800号-2

f1208.com 备案号:京ICP备14030918号-1

返回顶部