Javascript study notes (Math mathematical objects)

Math object
plain is a built-in objects related to perform mathematical operations, can not create an object using the new keyword.
Use its properties mainly Math. Attribute name , here are some common attributes

  • Math.random (): returns a random number between 0-1
  • Math.abs (parameter): returns the absolute value of parameter
  • Math.floor (parameter): The parameter is rounded down
  • Math.pow (parameter1, parameter2): Returns the power parameter1 parameter2 of
  • Math.round (parameter): parameter to rounding
  • Math.PI: Returns pi

Following completion of the above-described case of a small floor and random property (page random background: The background color using the RGB representation)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网页背景随机颜色</title>
		<script type="text/javascript">
			// 定义一个随机背景函数:onload属性:网页打开(刷新)时即调用函数
			window.onload = function(){
				var min = 0;
				var max = 256;
				// 创建三个0--255的随机整数
				var number1 = Math.floor(Math.random()*(max-min)+min);
				var number2 = Math.floor(Math.random()*(max-min)+min);
				var number3 = Math.floor(Math.random()*(max-min)+min);
				// 将rgb颜色表示弹出来
				// window.alert('rgb颜色表示为:rgb('+number1+','+number2+','+number3+')');
				// 设置背景
				document.body.bgColor = 'RGBColor('+number1,number2,number4+')';
			}
		</script>
	</head>
	<body>
	</body>
</html>

Published 63 original articles · won praise 1 · views 2035

Guess you like

Origin blog.csdn.net/qq_45061361/article/details/104390728