问答详情
源自:7-16 随机数 random()

Math问题:怎么设置成,我点一次,就更新一次数,我现在弄得是只能点一次

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mathint </title>
<script type="text/javascript">
var i=Math.random()*10;
function abc(){
    document.write(Math.round(i));
    }
</script>
</head>
<body>
<input type="button" value="刷新" onclick="abc()">
</body>
</html>


提问者:doits 2016-03-10 22:00

个回答

  • Deevan
    2016-03-10 23:12:15

    需要用到location对象里的reload()方法。语法是:location.reload()

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>编程练习</title>

    <script>

    var mynum=Math.random();

    Math.round(mynum*10);

    document.write(Math.round(mynum*10));


    function contxt()

    {

    location.reload();

    }


    </script>

    </head>

    <body>

    <button type="button" onclick="contxt()">点击这里</button>

    </body>

    </html>

  • 寒冰凌霜
    2016-03-10 22:50:15

    <!DOCTYPE html>

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Mathint </title>

    <script type="text/javascript">


    function abc(){

    var i=Math.random()*10;

        document.getElementById("abc").innerText=Math.round(i);

        }

    </script>

    </head>

    <body>

    <input type="button" value="刷新" onclick="abc()">

    <div id="abc"><div>

    </body>

    </html>