刷新后保持JQuery手风琴打开 [英] Keep JQuery accordion open after refresh

查看:142
本文介绍了刷新后保持JQuery手风琴打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个asp.net网站,我在里面放了一个jQuery手风琴。我的问题是,回发或刷新后,当前手风琴窗格关闭,页面重置所有东西。
这是我的jQuery代码:

I made an asp.net web site in which i put a jquery accordion. My Problem is that after a postback or a refresh, the current accordion pane closes and the page resets every things. This is my jQuery code :

jQuery(document).ready(function () {
    function close_accordion_section() {
        jQuery('.button').removeClass('active');
        jQuery('.accordion .accordion-section-content').slideUp(300).removeClass('open');
    }
    jQuery('.button').click(function (e) {
        var currentAttrValue = jQuery(this).attr('href'); 
        if (jQuery(e.target).is('.active')) {
            close_accordion_section();
        }
        else {
            close_accordion_section();
            jQuery(this).addClass('active');
            jQuery('.accordion ' + currentAttrValue).slideDown(300).addClass('open');
            document.getElementById('.accordion ' + currentAttrValue).scrollIntoView();

        }
        e.preventDefault();
    });
});

在回发或刷新后,我可以如何保持手风琴窗格打开?
在此先感谢

What can i do to keep my accordion pane opened after a postback or refresh ? Thanks in Advance

推荐答案

您遇到的问题是因为回发后asp.net刷新整个页面。
解决方案如下:

The problem you are facing is because after postback asp.net refreshes the whole page. Solutions for that would be:


  1. 使用UpdatePanel查找要更新的地点 http://msdn.microsoft.com/en-us/library /system.web.ui.updatepanel(v=vs.110).aspx ,它将阻止PostBack刷新您的页面。

  2. 在手风琴当前的回发中包含信息打开并打开

    • 或者从asp.net后端

    • 或者从javascript与ClientScriptManager.RegisterStartupScript(this.GetType(), AKey,MyFunction('paramToOpenTab');,true);

  1. Use UpdatePanel for the places you want to update http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel(v=vs.110).aspx that will prevent the PostBack from refreshing your page
  2. Include information in the postback which accordion is currently open and open it
    • either from asp.net backend
    • or from javascript with ClientScriptManager.RegisterStartupScript(this.GetType(), "AKey", "MyFunction('paramToOpenTab');", true);

这篇关于刷新后保持JQuery手风琴打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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