代码之家  ›  专栏  ›  技术社区  ›  Omar Jandali

使用本地计算机中的Jquery重新加载或刷新页面

  •  0
  • Omar Jandali  · 技术社区  · 6 年前

    我在本地机器上有一个html文档,我使用JQuery创建了一个按钮,并设置了按钮的点击。单击按钮时,我希望刷新当前index.html页面。

        var refreshButton = '<button id="refresh"> Refresh </button>';
        $body.append(refreshButton);
        $('#refresh').click(function(){
          refresh(forceGet);
        });
    

    我试过了, location.refresh(); window.location.refresh(); &安培; refresh(); 但他们没起作用。

    2 回复  |  直到 6 年前
        1
  •  1
  •   TechLemur    6 年前
    $body.append(refreshButton);
    

    必须是

    $('body').append(refreshButton);
    

    和window.location.reload(true);应该有效。试试这个:

    $( document ).ready(function() {
       $('body').append('<button id="refresh"> Refresh </button>');
       $('#refresh').click(function(){
          window.location.reload(true);
       });
    });
    
        2
  •  1
  •   Jim Wright    6 年前

    你需要使用 window.location.reload() .

    $('document').ready(() => {
        $('#last-date').html(new Date())
        $('#refresh').on('click', () => {
            console.log('Refreshing...')
            window.location.reload(true)
        })
    })
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <button id="refresh">Refresh</button>
    <p>Last loaded at <span id="last-date"></span></p>