2013-11-26 148 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>` 

这正是我需要做的,我不记得我发现它的链接虽然...

相关问题