生成1-10的随机数,
var a = Math.floor(Math.random() * 10); /*Math.floor 整数生成*/
alert('生成结果为:',+a);
完整代码:
<!DOCTYPE html>
<head>
<meta charset='UTF-8'>
<title>js1-100随机数生成</title>
</head>
<body>
<script>
var a = Math.floor(Math.random() * 100);
alert ('结果为:'+a);
</script>
</body>
</html>
有水一作。。
如果是1-10的话则 * 10