2011-02-24 35 views
0
/*Forum maintain scrollposition*/ 
$('#wpf-wrapper a').each(function() { 
    $(this).click(function() { 
     $(this).attr('href', $(this).attr('href') + "#wpf-wrapper"); 
    }); 
}); 

我希望我所有的鏈接都可以使用他的#wpf-wrapper部分來正常啓動,但是在最後使用#wpf-wrapper哈希來調用?jquery:fire href,但添加#hash它?

現在,當我點擊鏈接時鏈接不會被解除!

回答

2

可能會有所幫助。

$('#wpf-wrapper a').live('click',function() {  
    $(this).attr('href', $(this).attr('href') + "#wpf-wrapper");   
}); 

希望它有幫助。

+0

謝謝你,這個伎倆!不知道爲什麼,但live()處理程序使其工作。 – matt 2011-02-24 16:10:16

1

試試這個 - 它重寫鏈接在頁面加載,而不是點擊:

$(function() { 
    $('#wpf-wrapper a').each(function() { 
     $(this).attr('href', $(this).attr('href') + "#wpf-wrapper"); 
    }); 
}); 
+0

我已經試過了,沒有什麼區別!一旦我添加散列,鏈接不會被解僱! – matt 2011-02-24 16:09:07

0

你並不需要這樣做onclick

$('#wpf-wrapper a').each(function() { 
    this.href = this.href + '#wpf-wrapper'; 
}); 
1

你也可以做一個簡單的重定向

$('#wpf-wrapper a').live('click',function() {  
    window.location = $(this).attr('href') + "#wpf-wrapper";   
});