2013-11-26 145 views
2

我知道這個問題已經在這裏和其他許多地方問過,但是沒有一個提供的解決方案適用於我。我不確定是因爲我錯誤地實現了它們,還是因爲我的腳本有些問題。我正在使用jQuery UI,並且在我的頁面上有多個手風琴。我希望第二個手風琴的第一個標題從外部鏈接打開。這裏是我的腳本:從外部鏈接打開手風琴

<script type="text/javascript"> 
    $(function() { 
    $("#accordion").accordion({ 
     active: false, 
     collapsible: true, 
     heightStyle: "content", 
     navigation: true 
    }); 
    $("#accordion2").accordion({ 
     active: false, 
     collapsible: true, 
     heightStyle: "content", 
     navigation: true 
    }); 
    </script> 


    <div> 
    <h7 id="misc">Misc</h7> 
    <div id="accordion"> 
     <h3 id="rent"><a href="#rent"> ...text.... </a></h3> 
     <div><p> ...text... </p></div> 
    </div></div> 
    <div> 
    <h7 id="misc2">Misc2</h7> 
    <div id="accordion2"> 
     <h3 id="rent2"><a href="#rent2"> ...text.... </a></h3> 
     <div><p> ...text... </p></div> 
     <h3 id="rent3"><a href="#rent3"> ...text.... </a></h3> 
     <div><p> ...text... </p></div> 
    </div></div> 

我試圖改變我的第二個手風琴:

$("#accordion2").accordion("activate", '<%= Request.QueryString["id"] %>'); 
}); 

如這裏推薦:Link to open jQuery Accordion 而且也曾嘗試.accordion( 「激活」,window.location的。哈希值)也列在該網頁上,並嘗試添加附加功能:

$(document).ready(function() { 
location.hash && $(location.hash).active('true'); 

我也曾嘗試此處給出的示例:https://forum.jquery.com/topic/accordion-open-a-specific-tab-with-link-from-another-page。這不但對我不起作用,而且從第二次手風琴上的第二次下降中刪除了手風琴格式。

我對jQuery非常陌生,所以解決方案可能很簡單,但我已經嘗試了幾件事(我只列出了上面的幾個,因爲那些是我記得的)。

我也使用:site.com/page/one.html#rent2鏈接到下拉菜單,以防萬一這是問題所在。任何幫助,將不勝感激。謝謝!

回答

0

好的,我能弄清楚對我有用的東西。我原來的$(()的函數,用手風琴,我說:

`var hash = window.location.hash; 
    var anchor = $('a[href$="'+hash+'"]'); 
    if (anchor.length > 0){ 
     anchor.click(); 
    }` 

然後到我的html我說:

`<h3><a href="#rent" id="rent">...text...</a></h3>` 

這正是我需要做的,我不記得我發現它的鏈接雖然...

相關問題