Zurb-Foundation Maintain Tab State

2019-08-03 16:56发布

问题:

What's the best way to maintain the state of a Foundation tab on postback? Preferably a way that doesn't use cookies.

<dl class="tabs">
  <dd class="active"><a href="#simple1">Simple Tab 1</a></dd>
  <dd><a href="#simple2">Simple Tab 2</a></dd>
  <dd class="hide-for-small"><a href="#simple3">Simple Tab 3</a></dd>
</dl>
<ul class="tabs-content">
  <li class="active" id="simple1Tab">This is simple tab 1s content. Pretty neat, huh?</li>
  <li id="simple2Tab">This is simple tab 2s content. Now you see it!</li>
  <li id="simple3Tab">This is simple tab 3s content.</li>
</ul>

回答1:

This may not be the best solution but it works for my .Net project, maybe it could work for you.

<asp:HiddenField runat="server" ID="currentTab" Value="0" />

$(document).ready(function() {
    var tb = $(this).find("input[id*='currentTab']").val();
    if (tb == null) {
        tb = 0;
    }
    if (tb == 1) {
        //alert("Tab 1");
        tabName = "t4"
        window.location.hash = tabName;
        return false
    }
    if (tb == 2) {
        //alert("Tab 2");
        tabName = "t2"
        window.location.hash = tabName;
        return false
    }
    if (tb == 3) {
        //alert("Tab 3");
        tabName = "t3"
        window.location.hash = tabName;
        return false;
    }
});

Protected Sub Button_Click1(sender As Object, e As EventArgs) Handles Button.Click
currentTab.Value = "3"
End Sub