35

window.location.hash のハッシュを変更して「this.id」に置き換えることができるかどうか疑問に思っています。または、window.location 全体を変更する必要がありますか?

4

1 に答える 1

56

はい、できます。私は自分のサイトの1つで同様のことをしますが、のhref代わりにを使用しますが、同様idid機能します。簡単な例:

$('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();
});
于 2010-07-31T06:55:51.267 に答える