C# 在Asp.Net中使用简单选项卡时,回发后保留活动选项卡
我正在使用ASP.NET web应用程序。您可以在这里看到“简单”选项卡的名称 即使在回发之后,我也要保留活动选项卡 我试着写下面的代码,但没有进展C# 在Asp.Net中使用简单选项卡时,回发后保留活动选项卡,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,我正在使用ASP.NET web应用程序。您可以在这里看到“简单”选项卡的名称 即使在回发之后,我也要保留活动选项卡 我试着写下面的代码,但没有进展 $(document).ready(function () { debugger; //Default Action var activeTab; if (activeTab == undefined) { <-- Added by
$(document).ready(function () {
debugger;
//Default Action
var activeTab;
if (activeTab == undefined) { <-- Added by me but the variable activeTab is refreshing every time and is undefined for every post back.
$(".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 () {
debugger;
$("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
activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
$(文档).ready(函数(){
调试器;
//默认动作
var-activeTab;
如果(activeTab==undefined){经过大量跟踪
在asp.net页面中,使用以下隐藏字段
<asp:HiddenField ID="hdnActiveTab" runat="server" Value="0" />
现在修改代码如下
$(document).ready(function () {
//debugger;
//Default Action
var setActiveTab = $get("<%=hdnActiveTab.ClientID%>").value;
if (setActiveTab == 0) {
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
} else {$(".tab_content").hide();
switch (setActiveTab) {
case "#tab1":
$("ul.tabs li:eq(0)").addClass("active").show(); $(".tab_content:eq(0)").show();
break;
case "#tab2":
$("ul.tabs li:eq(1)").addClass("active").show(); $(".tab_content:eq(1)").show();
break;
case "#tab3":
$("ul.tabs li:eq(2)").addClass("active").show(); $(".tab_content:eq(2)").show();
break;
case "#tab4":
$("ul.tabs li:eq(3)").addClass("active").show(); $(".tab_content:eq(3)").show();
break;
}
}
//On Click Event
$("ul.tabs li").click(function () {
//debugger;
$("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 rel attribute value to identify the active tab + content
$get("<%=hdnActiveTab.ClientID%>").value = activeTab; //Preserve Active Tab Even After PostBack
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
$(文档).ready(函数(){
//调试器;
//默认动作
var setActiveTab=$get(“”).value;
如果(setActiveTab==0){
$(“.tab_content”).hide();//隐藏所有内容
$(“ul.tabs li:first”).addClass(“active”).show();//激活第一个选项卡
$(“.tab_content:first”).show();//显示第一个选项卡内容
}else{$(“.tab_content”).hide();
开关(setActiveTab){
案例“#表1”:
$(.tabs li:eq(0)”).addClass(“活动”).show();$(.tab_内容:eq(0)”).show();
打破
案例“#表2”:
$(“ul.tabs li:eq(1)”).addClass(“活动”).show();$(“.tab_内容:eq(1)”).show();
打破
案例“#表3”:
$(“ul.tabs li:eq(2)”).addClass(“活动”).show();$(“.tab_内容:eq(2)”).show();
打破
案例“#表4”:
$(“ul.tabs li:eq(3)”).addClass(“active”).show();$(“.tab_内容:eq(3)”).show();
打破
}
}
//点击事件
$(“ul.tabs li”)。单击(函数(){
//调试器;
$(“ul.tabs li”).removeClass(“active”);//删除任何“active”类
$(this).addClass(“active”);//将“active”类添加到所选选项卡
$(“.tab_content”).hide();//隐藏所有选项卡内容
var activeTab=$(this).find(“a”).attr(“href”);//查找rel属性值以标识活动选项卡+内容
$get(“”)。value=activeTab;//即使在回发后也保留活动选项卡
$(activeTab).fadeIn();//淡入活动内容
返回false;
});
});