I have following jquery to set the selected tab as active tab, but it is not quite working. Can anybody help me out there? Basically I used a hidden field to save the selected tab, and in the ready function I set it to active.
<script type="text/javascript">
$(document).ready(function() {
var tab = $get('selected_tab').value;
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:tab").addClass("active").show(); //Activate first tab
$(".tab_content:tab").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;
});
});
</script>
<div id="content">
<input typE="hidden" id="selected_tab" name="selected_tab" value="0" />
<ul class="tabs">
<li><a href="#tab1" onclick="document.getElementById('selected_tab').value=0;">Details</a></li>
<li><a href="#tab2" onclick="document.getElementById('selected_tab').value=1;">History</a></li>
开发者_JS百科 <li><a href="#attachmentcontent" onclick="document.getElementById('selected_tab').value=2;">Attachments</a></li>
</ul>
You'll have to set the value of the selected_tab in your server code, then show the tab[selected_tab_value] on document.ready
ascx
<asp:HiddenField runat="server" id="selected_tab" name="selected_tab" />
ascx.cs
int selectedtab = 5;
selected_tab.value = selectedtab.toString();
精彩评论