在 ASP.NET 回发后保持当前的 jQuery 手风琴窗格打开? [英] Keep the current jQuery accordion pane open after ASP.NET postback?

查看:11
本文介绍了在 ASP.NET 回发后保持当前的 jQuery 手风琴窗格打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 asp.net aspx 网页上有一个 jquery 手风琴.在窗格内,我有 asp.net 按钮.当我点击按钮时,我所在的窗格关闭并重新加载页面,默认为第一个窗格.我不介意重新加载,但是有没有办法在重新加载后保持当前窗格打开.现在,我只是在一个带有手风琴 ID 的 div 上调用手风琴().

I have a jquery accordion on an asp.net aspx weppage. Inside the panes, I have asp.net buttons. When I click on the button, the pane I was in, closes and reloads the page, defaulting to the first pane. I don't mind the reload, but is there a way to keep the current pane open after the reload. Right now, I am just calling accordion() on a div with the id of accordion.

推荐答案

您可以使用隐藏的输入字段在回发期间保留活动的手风琴索引,然后在手风琴的更改事件期间使用 javascript 填充它.

You could use a hidden input field to persist the active accordion index during postbacks, and then populate it using javascript during the change event of the accordion.

<asp:HiddenField ID="hidAccordionIndex" runat="server" Value="0" />

<script language="javascript" type="text/javascript">
    $(function(){
        var activeIndex = parseInt($('#<%=hidAccordionIndex.ClientID %>').val());

        $("#accordion").accordion({
            autoHeight:false,
            event:"mousedown",
            active:activeIndex,
            change:function(event, ui)
            {
                var index = $(this).children('h3').index(ui.newHeader);
                $('#<%=hidAccordionIndex.ClientID %>').val(index);
            }
        });
    });
</script>

您可能想出一种更有效的方法来在更改事件期间捕获活动索引,但这似乎有效.

You could probably come up with a more efficient way of capturing the active index during the change event, but this seems to work.

页面加载后,它会从隐藏字段中检索活动索引并将其存储在一个变量中.然后,它使用检索到的索引和自定义函数初始化手风琴以触发更改事件,每当激活新窗格时,该事件都会将新索引写入隐藏字段.

When the page has loaded it retrieves the active index from the hidden field and stores it in a variable. It then initialises the accordion using the retrieved index and a custom function to fire on the change event which writes a new index to the hidden field whenever a new pane is activated.

在回发期间,隐藏字段值保留在 ViewState 中,以便在再次加载页面时,手风琴会使用点击的最后一个窗格的索引进行初始化.

During a postback, the hidden field value is persisted in the ViewState so that when the page is loaded again the accordion is initialised with the index of the last pane clicked on.

这篇关于在 ASP.NET 回发后保持当前的 jQuery 手风琴窗格打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆