JS对象随机数 random() 方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之间的一个随机数。 注意:返回一个大于或等于 0但小于1的符号为正的数值
随机数 random()
任务
补充右边编辑器代码,在script标签内,使用random ()方法和round(),计算不大于10的整数。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
function getRandom(){
document.getElementById("num").innerHTML = Math.round(Math.random()*10);
}
</script>
</head>
<body>
<p id="num">7</p>
<input type="button" value="刷新取小于10的整数" onclick="getRandom()">
</body>
</html>

浙公网安备 33010602011771号