【技术】0-1000的随机数
控制台里显示0-1000的随机数:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test3</title>
<script src="js/jquery-1.11.1.min.js"></script>
</head>
<body>
<script>
function fn(){
//Math.random():0到1随机数
//Math.random()*1000:0到1000随机数
//Math.ceil(Math.random()*1000):向上取整
var str = Math.ceil(Math.random()*1000);
console.log(str);
//每1秒输出一个随机数
setTimeout("fn()",1000);
}
fn();
</script>
</body>
</html>

浙公网安备 33010602011771号