js更新页面,随机更新数字

代码1:

<script>
function getRandom(){
var i = Math.random()*40+160;
document.getElementById("num").innerText = window.parseInt(i);
}
</script>

<body onload="getRandom()">
<p id="num"></p>
</body>
View Code

代码2:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<style>
.number{ 
background:#FF6666;
width:30px;
height:30px;
line-height:30px;
border-radius:10px;
color: #fff;
text-align: center;

}
</style>
<script type="text/javascript">
function random(a, b) {
var r = Math.round(Math.random() * (b - a));
document.getElementById("number").innerHTML = a + r;
}
</script>
<title></title>
</head>
<body onload="random(50,200)">
<div id="number" class="number"></div>
</body>
</html>
View Code

 

posted @ 2016-09-12 15:36  林育松  阅读(284)  评论(0编辑  收藏  举报