<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>round()</title>
</head>
<body>
<p id="r">round()</p>
<h3>round()</h3>
<button onclick="myFunction()">盗墓笔记</button>
<script>
function myFunction(){
var h = Math.round(2.60);
document.getElementById("r").innerHTML=Math.h;
}
</script>
</body>
</html>
JavaScript Math(算数) 对象
round()
round() 方法将数字四舍五入到最接近的整数。
2.49将向下舍入 (9),而 2.60将向上舍入 (3)
语法
Math.round(h)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>random()</title>
</head>
<body>
<p id="a">random()</p>
<button onclick="myFunction()">沙海</button>
<script>
function myFunction(){
document.getElementById("a").innerHTML=Math.random();
}
</script>
</body>
</html>
JavaScript Math(算数) 对象
random()
random() 方法返回从 0(含)到 1(不含)的随机数
语法
Math.random()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>max()</title>
</head>
<body>
<p id="m">max()</p>
<button onclick="myFunction()">max()</button>
<script>
function myFunction(){
document.getElementById("m").innerHTML=Math.max(9,9);
}
</script>
</body>
</html>
JavaScript Math(算数) 对象
max()
max() 方法返回具有最高值的数字。
语法
Math.max(n1, n2, n3, ..., nX)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>min()</title>
</head>
<body>
<p id="n">min()</p>
<button onclick="myFunction()">min()</button>
<script>
function myFunction(){
document.getElementById("n").innerHTML=Math.min(6,9);
}
</script>
</body>
</html>
JavaScript Math(算数) 对象
min()
min() 方法返回具有最小值的数字
语法
Math.min(n1, n2, n3, ..., nX)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
function startTime(){
var dd=new Date();
var h=dd.getHours();
var d=dd.getMinutes();
var c=dd.getSeconds();
d=checkTime(d);
c=checkTime(c);
document.getElementById('盗墓笔记').innerHTML=h+":"+dd+":"+c;
cf=setTimeout(function(){startTime()},900);
}
function checkTime(y){
if (y<10){
y="0" + y;
}
return y;
}
</script>
</head>
<body onload="startTime()">
<div id="盗墓笔记"></div>
</body>
</html>
JavaScript Date(日期) 对象