使用jQuery刷新頁面


------------恢復內容開始------------

方法1:使用location.reload()

location.reload()方法重新加載當前web頁面,此方法類似於你瀏覽器上的刷新頁面按鈕。如果把該方法的參數設置為 true參數,可強制頁面從服務器加載並忽略瀏覽器緩存。

語法:

location.reload(true)

示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head>
  
<body>
    <h3 style="color: green">如何使用jQuery刷新頁面?</h3>
    <p>這是一段測試文本!</p>
          輸入文本:<input type="text" /><br /><br />
      
    <button type="button">重新加載頁面</button>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                location.reload(true);
                alert('Reloading Page');
            });
        });
    </script>
</body>
  
</html>

方法2:使用history.go(0)

history.go()方法根據傳遞給它的參數從瀏覽器歷史記錄中加載一個URL。如果傳遞的參數為“0”,則會重新加載當前頁。

語法:

history.go(0);

示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head> 
  
<body> 
    <h3 style="color: green">如何使用jQuery刷新頁面?</h3> 
    <p>這是一段測試文本!</p> 
          輸入文本:<input type="text" /><br /><br />
      
    <button type="button">重新加載頁面</button> 
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script> 
    <script type="text/javascript"> 
        $(document).ready(function () { 
            $("button").click(function () { 
                history.go(0); 
            }); 
        }); 
    </script> 
</body> 
  
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM