jquery
  • ajax
  • hash
  • history
  • 2010-09-30 94 views 0 likes 
    0

    我正在做組合的網站模板。我有關於我的完整ajax站點的「主動鏈接」的問題。活動菜單類當前頁面

    當我直接打開url(http://bit.ly/d5qNeN)時,url並沒有拿出addClass函數。

    我怎麼能添加「選擇」類直接打開網址嗎?

    這是我的jquery代碼,它將'選中的'類添加到我的導航欄中。

    $j("a[rel='history']").click(function(){ 
    $j("a[rel='history']").addClass('selected').not(this).removeClass('selected'); 
    
        // Get the hash from the link that was clicked 
        // jQuery.history.load("new-hash-value"); 
        var hash = $j(this).attr('href'); 
        hash = hash.replace(/^.*#/, ''); 
    
        // Load this hash with the history plugin 
        $j.historyLoad(hash); 
        $j('#load').fadeIn('normal'); 
        if(!$j('#load').get(0)) { 
         $j('#content').append('<div id="load"></div>'); 
        } 
    
        return false; 
    }); 
    

    回答

    0
    $j(function() { // on DOM ready 
        hash = location.hash; // everything after a # in the URL 
        if(hash) { 
        // "click" on menu entry that links to expected target 
        $j("a[rel='history'][href="+hash+"]").trigger("click"); 
        } 
    }); 
    
    +0

    對不起,我不明白我的意思。你能告訴我確切的位置嗎?因爲我在everyline想你的代碼,它不工作了 – mrpn 2010-10-04 11:57:05

    +0

    哦,我的錯:應該是的location.hash,而不是HREF。我改變了這一點。 – elektronikLexikon 2010-10-04 14:23:15

    +0

    耶!有用。非常感謝 :) – mrpn 2010-10-04 20:40:53

    相關問題