2010-07-31 22 views

回答

46

是的,你可以。我在我的一個網站上做了類似的事情,雖然href而不是id,但id也可以。一個簡單的例子:

$('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

很好:-)非常感謝! – circey 2010-07-31 07:07:30

+0

這是跨瀏覽器嗎? – jldupont 2013-04-05 17:17:22

+0

@jldupont:我應該這樣想。 – BoltClock 2013-04-05 17:18:12