Show/Hide button (text) for Accordion
Have an accordion with a "view" button to open close the accordion panel (using jQuery Tools), but I would like to have dynamic text that says "show/hide" depending on the state...
Here is the code for the accordion in asp.NET
<div id="accordion">
<% foreach (var eventModel in ViewModel)
{ %>
<% var isNewMonth = eventModel.Date.Month != previousMonth; %>
<% if (isNewMonth && previousMonth > 0)
{ %></table></div><% } %>
<% previousMonth = eventModel.Date.Month; %>
<% if (isNewMonth)
{ %>
<h2><%= string.Concat(eventModel.Date.ToString("MMMM"), " ", eventModel.Date.Year) %> <span style="float:right;"><a href="#" class="button blue small">View</a></span></h2>
<div class="pane" style="display:block">
<table id="listTable" width="100%" cellpadding="3" cellspacing="0" border="0">
<tr align="left" valign="top"><th align="left" valign="top">Date</th><th align="left" valign="top">Event</th><th align="left" valign="top">Event Type</th></tr>
<% } %>
<tr align="left" valign="top"><td align="left" valign="top"><b><span id="date" style="float:left;"> <%= string.Concat(eventModel.Date.ToString("MMMM"), " ", eventModel.Date.Day, " </span><span id='day' style='float:left'>" + eventModel.Date开发者_运维问答.DayOfWeek + "</span> ")%></b></td><td align="left" valign="top" ><%= Html.ActionLink(eventModel.Name.Truncate(40), "event", "register", new { id = eventModel.Id }, null)%></td><td align="left" valign="top"><%= string.Concat(" ", eventModel.Sport)%></td></tr>
<% } %>
<% if (ViewModel.Count > 0)
{ %></table></div><% } %>
</div>
Here is the initialization script using jQuery:
$(function() { $("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0}); $(".small").click(function() { moveToTop(); }); });
You can use the toggle-Method: http://api.jquery.com/toggle/
Note if you didnt want to deal with alot of script you could use the icon option in the accordian and display an image that says show/hide.
look here
http://jqueryui.com/demos/accordion/#option-icons
Edited
For a show/Hide label on the tab when selected
$( "#accordian" ).tabs("#accordion div.pane",
{tabs: 'h2',
effect: 'slide',
initialIndex: 0
select: function(event, ui) {
//ui.panel is the current tab I think
//you should be able to toggle a show/hide on each tab from here
}
}
);
精彩评论