简单的生成随机数
<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> //生成0-10的随机数 乘10 加1得到的是浮点数 var random = Math.random() * 10 + 1; // console.log(random); // 向下取整 var ran = Math.floor(random); console.log(ran); </script> </body> </html>