如何跟踪手风琴(母版中)打开状态的页面导航之后? [英] how to keep track of accordion(in masterpage) open status after page navigation?
问题描述
我使用jQuery的手风琴在asp.net母版的菜单。
i am using jquery accordion as a menu in asp.net Masterpage.
这是jQuery的
$(document).ready(function() {
$(".header").click(function() {
$(this).toggleClass("display");
$(this).next("div .menu_body").slideToggle(500);
});
});
这是HTML。
<div id="MasterPage_Menu" class="menu_list">
<p class="header">Header-1</p>
<div class="menu_body">
<a href="page1.aspx">Link-1</a>
</div>
<p class="header">Header-2</p>
<div class="menu_body">
<a href="page2.aspx">Link-2</a>
</div>
<p class="header">Header-3</p>
<div class="menu_body">
<a href="page3.aspx">Link-3</a>
</div>
</div>
据的code以上,被点击的标题时,内容(menu_body)将被滑动肘节。
该menu_body是躲在默认情况下,当在头中的用户点击,则menu_body是可见的。
According the code above, when the header is clicked, the content (menu_body) will be slided toggle. The menu_body is hide at default, when the user click on the header, the menu_body is visible.
示例问题:如:2 menu_body是可见的,当我点击HREF =page1.aspx这个,该页面将被导航到page2.aspx但手风琴将返回到默认的是哪个所有的menu_body是隐藏的。
Example Problem: eg: 2 menu_body is visible, when i click on href = "page1.aspx", the page will be navigated to page2.aspx but the accordion will return to be default which all the menu_body is hidden.
由于我在母版页使用该手风琴,我不存储值跟踪的手风琴menu_body身份进入hiddenfield当页面导航了。在hiddenfield值将被重置。
Since I am using this accordion in master page, i fail to store the value to keep track of the accordion menu_body status into the hiddenfield when the page is navigated away. The value in hiddenfield will be reset.
我想存储该会话,但在客户端页面,它不会让我们来存储值到会话中。
I am thinking to store this in session, but in client page, it doesn't allow us to store value into the session.
这个解决的办法?
推荐答案
如果您添加 ID
属性页眉:
<p class="header" id="header-1">Header-1</p>
<div class="menu_body">
<a href="page1.aspx">Link-1</a>
</div>
然后就可以拉 ID
出在你的处理程序,并使用的 jquery.cookie
跟踪的cookie打开面板:
Then you can pull the id
out in your handler and use jquery.cookie
to track the open panel in a cookie:
$(".header").click(function() {
var $this = $(this);
if(!$this.hasClass('display'))
$.cookie('open_panel', this.id);
$this.toggleClass("display");
$this.next("div .menu_body").slideToggle(500);
});
您会需要与 open_panel
一点,如果你想有多个面板在同一时间开放,但一个简单的CSV列表可能就足够存储格式播放;我会离开的那部分作为一个练习留给读者。您还会想检查Cookie在页面加载时并打开相应的面板。
You'd need to play with the storage format for open_panel
a bit if you want to have multiple panels open at one time but a simple CSV list would probably suffice; I'll leave that part as an exercise for the reader. You'd also want to check the cookie when the page loads and open the appropriate panels.
您还可以跟踪cookie的服务器上的价值,如果你想保持周围设置为用户的帐户preferences的一部分。
You could also keep track of the cookie's value on the server if you wanted to keep the setting around as part of the user's account preferences.
这篇关于如何跟踪手风琴(母版中)打开状态的页面导航之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!