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 == 'admin'){ if(userPwd.value == 'admin'){ if(yzm.value == span.innerHTML){ location.href = 'login.html' }else{ alert('验证码不对') } }else{ alert('密码不能为空') } }else{ alert('用户名不能为空') } }
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!