本文主要记录一下学习JavaScript的时候的学习笔记。
1.效果展示
2.源代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function ope(){
document.getElementById("demo").innerHTML=Math.round(2.6);
document.getElementById("demo1").innerHTML=Math.random();
document.getElementById("demo2").innerHTML=Math.max(1,1.2);
document.getElementById("demo3").innerHTML=Math.min(3,4);
document.getElementById("demo4").innerHTML="";
}
</script>
<div id="demo">1</div>
<div id="demo1">1</div>
<div id="demo2">1</div>
<div id="demo3">1</div>
<div id="demo4">1</div>
<input type="button" onclick="ope()" value="点我点我">
</body>
</html>
3.实现任意范围的随机数
①.0-10随机数
document.getElementById(“demo1”).innerHTML=Math.round(Math.random()*10);
②5-10随机数
document.getElementById(“demo1”).innerHTML=Math.round(Math.random()*10+5);
|