jQuery的回传,保持回发后同一选项卡 [英] Jquery postback, maintain same tab after postback

查看:183
本文介绍了jQuery的回传,保持回发后同一选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery标签并按照JS的方法,如何和什么我可以对其进行修改,以保持回发之间标签的状态呢? (这将重置选项卡的Page_Load后第一个选项卡)

  $(文件)。就绪(函数(){

        //当页面加载...
        $(tab_content)隐藏()。 //隐藏所有内容
        $(ul.tabs李:第一)addClass(活动)显示()。 //激活第一个选项卡
        $(。tab_content:第一)显示()。 //显示第一个选项卡的内容

        //在Click事件
        $(ul.tabs李)。点击(函数(){

            $(ul.tabs李)removeClass移除(活动)。 //删除任何积极级
            $(本).addClass(活性); //添加积极级到选定的标签
            $(tab_content)隐藏()。 //隐藏所有选项卡的内容

            变种activeTab = $(本).find(一)ATTR(的href); //查找href属性值来确定当前标签+内容
            $(activeTab).fadeIn();在活动ID的内容//淡出
            返回false;
        });
 

解决方案

您可以跟踪使用Javascript在一个隐藏字段的活动选项卡,然后选中隐藏字段时,页面加载。 (此外在Javascript)

另外,你可以使用的UpdatePanel与ASP.Net AJAX来消除回发。 (请注意,如果接头是一个更新面板,它们将无法正常工作)

I'm using jquery tab and following js method, how and what can i modify it to maintain state of tab between postbacks? (This resets tabs to first tab after page_load)

$(document).ready(function() {

        //When page loads...
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content

        //On Click Event
        $("ul.tabs li").click(function() {

            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        }); 

解决方案

You can track the active tab in a hidden field using Javascript, then check the hidden field when the page is loaded. (Also in Javascript)

Alternatively, you can use UpdatePanels with ASP.Net AJAX to eliminate the postbacks. (Note that if the tabs are in an update panel, they won't work correctly)

这篇关于jQuery的回传,保持回发后同一选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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