美文网首页
js 刷新当前页面的三种方式

js 刷新当前页面的三种方式

作者: 丶灰太狼他叔 | 来源:发表于2018-03-22 14:28 被阅读34次

    1、reload() 方法

    reload()方法用于刷新当前文档。
    reload() 方法类似于你浏览器上的刷新页面按钮。

    location.reload();
    

    2、replace() 方法

    replace() 方法可用一个新文档取代当前文档。。和href类似,就是一个跳转。不过没有后退。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    <script>
    function replaceDoc()
    {
        window.location.replace("http://www.runoob.com")
    }
    </script>
    </head>
    <body>
    
    <input type="button" value="载入新文档替换当前页面" onclick="replaceDoc()">
    
    </body>
    </html> 
    

    3、meta中也只页面自动刷新

    <meta http-equiv="refresh" content="5">
    

    注:equiv == equivalent,为等价的意思。

    转自:http://www.runoob.com/w3cnote/js-refresh-current-page.html

    相关文章

      网友评论

          本文标题:js 刷新当前页面的三种方式

          本文链接:https://www.haomeiwen.com/subject/qxeaqftx.html