案例:数学对象

来自CloudWiki
跳转至: 导航搜索

Math Math.PI 圆周率 Math.SQRT1_2 返回返回 2 的平方根的倒数(约等于 0.707)。 Math.SQRT2 返回 2 的平方根(约等于 1.414)。 Math.E 返回算术常量 e,即自然对数的底数(约等于2.718)。 Math.LN2 返回 2 的自然对数(约等于0.693)。 Math.LN10 返回 10 的自然对数(约等于2.302)。 Math.LOG2E 返回以 2 为底的 e 的对数(约等于 1.414)。 Math.LOG10E 返回以 10 为底的 e 的对数(约等于0.434)。 Math.max(x,y,...) 返回最大值 Math.min(x,y,...) 返回最小值 Math.pow(x,y) 返回x的y次方 Math.floor(3.4)//3 下取整 Math.ceil(3.4)//4 上取整 Math.round(x) 对x进行四舍五入 Math.random() 返回0-1之间的数,不包含0和1 Math.sqrt(x) 返回数的平方根。 Math.sin(x) 方法可返回一个数字的正弦 必需。一个以弧度表示的角。将角度乘以 0.017453293 (2PI/360)即可转换为弧度。 参数 x 的正弦值。返回值在 -1.0 到 1.0 之间。 Math.cos(x) 方法可返回一个数字的余弦值。 x 的余弦值。返回的是 -1.0 到 1.0 之间的数。


<!DOCTYPE html> <html> <head> <title>数学对象</title> <meta charset="utf-8"> <style>

       .box{
           width:300px;
           height:200px;
           margin:0 auto;
           border:1px solid red;
           border-radius:10px;
           text-align:center;
       }
       .box p{
           margin: 0;
           padding:0;
           line-height:100px;
           text-align:center;
           font-weight:900;
           font-size:36px;
       }
       .box input{
           width:70px;
           height:40px;
       }
   </style>

</head> <body>

<script> console.log(Math.max(3,4,5,6,7,8,9,10)) console.log(Math.min(3,4,5,6,7,8,9,10)) console.log(Math.pow(2,3)) console.log(Math.floor(3.0)) console.log(Math.ceil(3.8)) console.log(Math.round(3.8)) console.log(Math.random()) console.log(Math.floor(Math.random()*10)) console.log(Math.sqrt(3)); console.log(Math.sin(2*Math.PI/12)); console.log(Math.cos(2*Math.PI/6)); </script>

请点击开始按钮

   <input type="button" value="start">
   <input type="button" value="stop">

<script>

   var arr=["赵楠","张三水","牛三金","原文武","高朋鸟","陈志强","刘振梅"];
   var timer;
   document.getElementsByTagName("input")[0].onclick=function(){
       clearInterval(timer);
       timer=setInterval(function(){
           var num=Math.floor(Math.random()*arr.length);
           document.getElementsByTagName("p")[0].innerText=arr[num];
       }, 10);
   }
   document.getElementsByTagName("input")[1].onclick=function(){
       clearInterval(timer);
   }

</script> </body> </html>