簡體   English   中英

使用Jquery從本地計算機重新加載或刷新頁面

[英]Reload or Refresh a page using Jquery from local machine

我在本地計算機上有一個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(); 但他們沒有工作。

您需要使用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> 

$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);
   });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM