如何使用jQuery刷新页面?

如何使用jQuery刷新页面?下面本篇文章就来给大家介绍一下使用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>

效果图:

1.gif

方法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>

效果图:

2.gif

相关推荐:

angularjs教程

golang教程

redis入门教程

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值