Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何自动刷新HTML页面一次_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何自动刷新HTML页面一次

Javascript 如何自动刷新HTML页面一次,javascript,jquery,html,Javascript,Jquery,Html,此脚本每5秒手动和自动刷新一次页面。如何使页面在5秒后自动重新加载页面一次 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>

此脚本每5秒手动和自动刷新一次页面。如何使页面在5秒后自动重新加载页面一次

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Refresh or Reload a Page Using JQuery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    </head>
    <body>
        <div><input id="btReload" type="button" value="Reload Page" /></div>
    </body>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#btReload').click(function() { location.reload(true); });    // RELOAD PAGE ON BUTTON CLICK EVENT.

            // SET AUTOMATIC PAGE RELOAD TIME TO 5000 MILISECONDS (5 SECONDS).
            setInterval('refreshPage()', 5000);
        });
        function refreshPage() { location.reload(); }
    </script>
    </html>

使用JQuery刷新或重新加载页面
$(文档).ready(函数(){
$('#btReload')。单击(函数(){location.reload(true);})//在按钮单击事件上重新加载页面。
//将自动页面重新加载时间设置为5000毫秒(5秒)。
setInterval('refreshPage()',5000);
});
函数refreshPage(){location.reload();}

使用setTimeout代替setInterval,语法相同

    <script type="text/javascript">
    $(document).ready(function() {
        $('#btReload').click(function() { location.reload(true); });   

        // SET AUTOMATIC PAGE RELOAD TIME TO 5000 MILISECONDS (5 SECONDS).
        setTimeout('refreshPage()', 5000);
    });
    function refreshPage() { location.reload(); }

$(文档).ready(函数(){
$('#btReload')。单击(函数(){location.reload(true);});
//将自动页面重新加载时间设置为5000毫秒(5秒)。
setTimeout('refreshPage()',5000);
});
函数refreshPage(){location.reload();}

执行以下修改:

var timerId = setInterval('refreshPage()', 5000);
并更改刷新页面功能

function refreshPage() { clearInterval(timerId); location.reload(); }

谢谢大家。你们太棒了
$(document).ready(function () {
$('#btReload').click(function () { location.reload(true); });    // Manual

TimeSet(); // Auto Once});

function TimeSet() {
setTimeout(function () {
    // Do something after 5 seconds
    Refresh()
}, 5000);}

function Refresh() {
location.reload();}