使用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