Home  >  Article  >  Web Front-end  >  Explain content related to mathematical objects Math

Explain content related to mathematical objects Math

jacklove
jackloveOriginal
2018-06-11 17:42:141558browse

Mathematical object Math

1. Method

1》 Math.min(parameter 1, parameter 2, parameter 3) Find the minimum value among the parameters

2》 Math.max(parameter 1, parameter 2, parameter 3) Find the maximum value among the parameters

3》 Math.floor() Get the integer by discarding the decimals

4》 Math.ceil() If there is a decimal point, round to 1 (drop the decimal part and get the integer part 1)

5》 Math.abs() Get the absolute value

6》 Math.sqrt() Square root

7》 Math.random() Random number (range 0-1)

8》 Math.round() Rounding

//数学对象Math
/*var min = Math.min(3,5,6,1);//求出参数中最小值
document.write(min)
var max = Math.max(33,44,88,29);//求出参数中最大值
document.write(max)
*/
/*
var num1 = 3.1415926;
document.write(Math.floor(num1));//舍掉小数得到整数
document.write(parseInt(num1))
document.write(Math.ceil(num1));//有小数点就进1取整(舍去小数部分,得到整数部分+1)
var num1= -5
document.write(Math.abs(num1));//取绝对值
var num2 = 64
document.write(Math.sqrt(num2));//开平方
*/
//document.write(Math.random());//随机数 (范围0-1之间)
//案例 范围是0-5之间的随机数
//document.write(Math.floor(Math.random()*5));
/*var num = 3.5
document.write(Math.round(num)); //四舍五入
*/
//案例 表单随机验证码
var span = document.getElementById('span'),
	btn  = document.getElementById('btn'),
	userName = document.getElementById('userName'),
	userPwd = document.getElementById('userPwd'),
	yzm = document.getElementById('yzm');
var str = 'abcdefghigklmnopqrstuvwxyz1234567890';
var str1 = '';
for(var i = 0; i < 4 ;  i ++ ){
	str1 += str[Math.floor(Math.random()*str.length)]
}
span.innerHTML =str1;
// Math.floor(Math.random()*9000)+1000 ;//innerHTML 往元素中 写入html代码
//document.write( 	Math.floor(Math.random()*9000)+1000 );
btn.onclick = function(){
	if(userName.value == &#39;admin&#39;){
		if(userPwd.value == &#39;admin&#39;){
			if(yzm.value == span.innerHTML){
				location.href = &#39;login.html&#39;
				
			}else{
				alert(&#39;验证码不对&#39;)
			}
		}else{
			alert(&#39;密码不能为空&#39;)
		}
	}else{
		alert(&#39;用户名不能为空&#39;)
	}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!--案例
用户名
密码
验证码===》数字4位数的随机 (混合  数字 字母 4位数随机)
以上所有内容都完成 都为true ====>登录 跳转页面-->
<form action="" method="post">
用户名  <input type="text" id="userName"/><br />
密码 <input type="password" id="userPwd"/><br />
验证码 <input type="" name="" id="yzm" value="" /><span id=&#39;span&#39;></span><br />
<input type="button" name="" id="btn" value="登录" /><br />
</form>
<script src="script.js"></script>
</body>
</html>

This article explains the mathematical object Math For related content, please pay attention to php Chinese website for more related content.

Related recommendations:

Explanation on the difference between JS and JSP

Explanation of this in Javascript

Detailed explanation about uploading word, txt, Excel, PPT and other files to WeChat applet

The above is the detailed content of Explain content related to mathematical objects Math. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn