jQuery-Collapse与标题中的链接
我使用Daniel Stocks jQuery-Collapse with cookies,效果很好。
https://github.com/danielstocks/jQuery-Collapse
嗨,有谁知道如何将其中一个标题作为链接? 因此,当单击它时,它链接到另一个也包含菜单的页面,当加载此页面时,单击的菜单将展开,显示子项。
在下面的示例中,我需要水果链接到另一个页面并在此页面进行扩展:
任何帮助,将不胜感激 :-)
我看到的另一个问题是插件会忽略h3中的链接。
所以你需要将它与自定义show()处理程序结合起来。
HTML
Fruits
- Apple
- Pear
- Orange
...
JS
$(".demo").collapse({ head: "h3", group: "ul", show: function() { if($(this).prev().attr('rel')){ // open a window with the rel value as the location. window.location=($(this).prev().attr('rel')); } $(this).show() }, hide: function(){ $(this).hide() } });
然后使用@Andrea提到的方法,只需将要在另一个页面中打开的项目设置为活动状态即可。
所以在这个例子中,如果url是#fruits,那么我们在加载时打开的项目将是id =“fruits”的h3
要做到这一点,你可以使用。
if(window.hash){ $("#"+window.hash).addClass('active')
您可以在a href="default2.html#id"
一个id并将其设置为下一个ul id="id"
以这种方式使用javascript你可以在加载时显示正确的列表。
看看这里