写了一个循环里面数字随机显示
<script type="text/javascript">
for(var i=0;i<10;i++){
for(var j=0;j<10;j++){
document.write("<div class='test3'>"+parseInt(10*Math.random())+"</div>");
}
document.write("<br />");
document.write("<div class='clear'></div>");
}
</script>
<style>
.test3{width:30px;height:30px;background:#ccc; float:left;}
</style>
但是想要获得新的随机数就得刷新一下页面,我知道刷新页面获得随机数的办法,想知道可不可以只刷新这一个代码区域获得随机数而不是刷新页面
js如何刷新当前区域
答案:2 悬赏:0 手机版
解决时间 2021-02-08 17:04
- 提问者网友:几叶到寒
- 2021-02-08 00:09
最佳答案
- 五星知识达人网友:枭雄戏美人
- 2021-02-08 01:42
<!DOCTYPE HTML>
<html>
<head>
<meta charset=gb2312>
<title>Nothing</title>
<style type="text/css">
div.test3 {
border: 1px solid black;
margin: auto;
text-align: center;
width: 30px;
height: 30px;
background: #ccc;
float: left;
}
</style>
<script type="text/javascript">
var check = function ()
{
var body = document.body;
body.innerHTML = '';
for ( var i = 0; i < 10; i++)
{
for ( var j = 0; j < 10; j++)
{
body.innerHTML += ("<div class='test3'>" + parseInt (10 * Math.random ()) + "</div>");
}
body.innerHTML += ("<br />");
body.innerHTML += ("<div class='clear'></div>");
}
}
onload = function ()
{
setInterval (function ()
{
check ();
}, 1000);
}
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<meta charset=gb2312>
<title>Nothing</title>
<style type="text/css">
div.test3 {
border: 1px solid black;
margin: auto;
text-align: center;
width: 30px;
height: 30px;
background: #ccc;
float: left;
}
</style>
<script type="text/javascript">
var check = function ()
{
var body = document.body;
body.innerHTML = '';
for ( var i = 0; i < 10; i++)
{
for ( var j = 0; j < 10; j++)
{
body.innerHTML += ("<div class='test3'>" + parseInt (10 * Math.random ()) + "</div>");
}
body.innerHTML += ("<br />");
body.innerHTML += ("<div class='clear'></div>");
}
}
onload = function ()
{
setInterval (function ()
{
check ();
}, 1000);
}
</script>
</head>
<body>
</body>
</html>
全部回答
- 1楼网友:一把行者刀
- 2021-02-08 02:52
可以将这段代码(for(var i=0;i<10;i++){
for(var j=0;j<10;j++){
document.write("<div class='test3'>"+parseInt(10*Math.random())+"</div>");
}
document.write("<br />");
document.write("<div class='clear'></div>");
})放在函数里,需要刷新的时候调用即可
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯