Highlighting the selected jquery tab using asp.net Master page

匆匆过客 提交于 2019-12-22 16:44:07

问题


I am using jquery tabs(First,Second,Third) in multiple asp.net pages (First.aspx, second.aspx,Third.aspx) in my asp.net website and in each page i am writing the ul,li code. For example in the First.aspx page I am writing the following code inside the 'ul' tag

<li class="current"><a href="#First">First tab</a></li>
 <li><a href="Second.aspx">Second tab</a></li>
 <li><a href="Third.aspx">Third tab</a></li>

Similarly in the second.aspx,Third.aspx pages i am using the Class="current" to highlight the selected tab.Recently we have planned to move to Master pages.So the master page should contain the ul,li code for the tabs.But the problem is that I do not understand how to apply the class="current" to the selected tab,in the case of the master page.Could someone please help?

Thanks in advance.


回答1:


Write a javascript function in your master page to set the current class on a tab. Each page can then call that function when it's loaded to set the current page.

Something like:

<li id='tab1'><a href="#First">First tab</a></li>
<li id='tab2'><a href="Second.aspx">Second tab</a></li>
<li id='tab3'><a href="Third.aspx">Third tab</a></li>


function setCurrentTab(selectedTab) {
    $('li').removeClass('selected');
    $('[id=selectedTab]').addClass('selected');
}

and in Second.aspx, for example:

setCurrentTab('tab2');


来源:https://stackoverflow.com/questions/2085911/highlighting-the-selected-jquery-tab-using-asp-net-master-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!