是否有可能有一个正常的链接指向当前位置?

我目前找到了2个解决方案,但其中一个包括JavaScript,在另一个你必须知道页面的绝对路径:

<a href="#" onclick="window.location.reload(true);">1</a>
<a href="/foobar/">2</a>
<a href="#">3 (of course not working)</a>

有没有办法做到这一点,而不使用JavaScript或知道绝对路径?


当前回答

我使用JS在jekyll网站的标签页中仅显示具有特定id的div。对于同一页面中的一组链接,您可以显示相应的元素:

function hide_others() {
    $('div.item').hide();
    selected = location.hash.slice(1);
    if (selected) {
        $('#' + selected).show();
    }
    else {
    $('div.item').show();
    }
}

链接使用如下链接:

<a href="javascript:window.location.href='/tags.html#{{ tag[0] }}-ref'; hide_others()">{{ tag[0] }}</a>

其他回答

试试这个

<a href="javascript:window.location.href=window.location.href">

你可以这样做:<a href=""> this page</a> .

但我认为它不会保留GET和POST数据。

我使用JS在jekyll网站的标签页中仅显示具有特定id的div。对于同一页面中的一组链接,您可以显示相应的元素:

function hide_others() {
    $('div.item').hide();
    selected = location.hash.slice(1);
    if (selected) {
        $('#' + selected).show();
    }
    else {
    $('div.item').show();
    }
}

链接使用如下链接:

<a href="javascript:window.location.href='/tags.html#{{ tag[0] }}-ref'; hide_others()">{{ tag[0] }}</a>

<a href="/">单击me刷新页面</a>

< a href = "吗?">点击我重新加载页面</a> .

您可以使用表单对相同的URL进行POST。

 <form  method="POST" name="refresh" id="refresh">
 <input type="submit" value="Refresh" />
 </form>

这为您提供了一个刷新当前页面的按钮。这有点烦人,因为如果用户按下浏览器刷新按钮,他们会得到一个是否要重新提交表单的消息。