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

      

  • 相关阅读:
    数据库第1,2,3范式学习
    node.js安装及小例子
    WorkSkill整理之 技能体系
    PTE 准备之 Read aloud
    PTE 准备之 Personal introduction
    PTE准备的时候,用英式英语还是美式英语
    sqlserver2014无法打开报Cannot find one or more components_修复方案
    beego 框架用的页面样式模板
    Go语言开发中MongoDB数据库
    xmind8 破解激活教程
  • 原文地址:https://www.cnblogs.com/gechen/p/12682810.html
Copyright © 2020-2023  润新知