zoukankan      html  css  js  c++  java
  • JS笔记008

    第08章 数学对象

    8.1 数学对象简介

    Math.属性
    Math.方法
    

    8.2Math对象的属性

    PI
    LN2
    LN10
    LOG2E
    LOG10E
    SORT2
    SORT1_2
    
    120*Math.PI/180 //120度,牢记
    

    8.3Math对象的方法

    max(a,b,...n)
    min(a,b,...n)
    random()
    

    8.4最大值与最小值

    Math.max(a,b,...n)
    Math.min(a,b,...n)
    

    8.5取整运算

    向下取整:floor()
    向上取整:ceil()
    

    8.6三角函数

    sin(x)
    cos(x)
    tan(x)
    ...
    

    8.7生成随机数

    Math.random()
    

    8.8生成随机验证码

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<title>生成4位随机验证码</title>
    	</head>
    	<body>
    		<script>
    			var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    			var arr = str.split("");
    			var result = "";
    			for (var i=0; i<4; i++)
    			{
    				var n = Math.floor(Math.random() * arr.length);
    				result += arr[n];
    			}
    			document.write(result);
    		</script>
    	</body>
    </html>
    

    8.9生成随机颜色值

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    		<script>
    			function getRandomColor()
    			{
    				var r = Math.floor(Math.random() * (255 + 1));
    				var g = Math.floor(Math.random() * (255 + 1));
    				var b = Math.floor(Math.random() * (255 + 1));
    				var rgb = "rgb(" + r + "," + g +"," + b + ")";
    				return rgb;
    			}
    
    			document.write(getRandomColor());
    		</script>
    	</head>
    	<body>
    	</body>
    </html>
    
  • 相关阅读:
    CF919F A Game With Numbers
    CF1005F Berland and the Shortest Paths
    CF915F Imbalance Value of a Tree
    CF1027F Session in BSU
    CF1029E Tree with Small Distances
    CF1037E Trips
    CF508E Arthur and Brackets
    CF1042F Leaf Sets
    [HNOI2012]永无乡
    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理
  • 原文地址:https://www.cnblogs.com/infuture/p/13548509.html
Copyright © 2011-2022 走看看