possible to replace [removed].hash?

前端 未结 1 2095
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 22:15

I\'m wondering whether it\'s possible to change the hash in window.location.hash and replace it with \'this.id\'. Or would I need to change the entire window.location?

相关标签:
1条回答
  • 2021-02-06 23:04

    Yes, you can. I do something similar at one of my sites, although with href instead of id, but id works too. A quick example:

    $('a[id]').click(function(e)
    {
        // This will change the URL fragment. The change is reflected
        // on your browser's address bar as well
        window.location.hash = this.id;
        e.preventDefault();
    });
    
    0 讨论(0)
提交回复
热议问题