【问题标题】:How to reload page when hash.location are the same javascripthash.location 相同时如何重新加载页面 javascript
【发布时间】:2021-07-10 15:20:57
【问题描述】:

我有一个放置哈希 (#feed) 的按钮,当我在这个页面上时我想要它,当再次单击该按钮时,它会重新加载带有该哈希 (#feed) 的页面。

有什么办法吗?

【问题讨论】:

    标签: javascript html jquery url-fragment


    【解决方案1】:

    您可以触发onclick 事件并使用location.reload(); 刷新页面:

    function reload(e){
        e.preventDefault();
        location.href = e.target.href;
        location.reload();
    }
    a {
        display: block;
        width: 100px;
        height: 25px;
        background: lightgray;
        text-align: center;
        border-radius: 5px;
    }
    <a href="#feed" onclick="reload(event);">ok</a>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-21
      • 2020-08-12
      • 2011-05-15
      • 2011-04-12
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多