回发jquery后维护标签

时间:2014-01-30 22:59:40

标签: jquery asp.net

您好我尝试了不同的方式,但没有工作,任何人都可以帮助我

<script src="../Scripts/jquery1.9.1.js"></script>
<script src="../Scripts/jquery-ui.js"></script>
<div id="tabContainer">
    <asp:HiddenField ID="tab_index" runat="server" />
    <ul>
        <li><a href="#tabs-1">Tab 1</a>
        </li>
        <li><a href="#tabs-2">Tab 2</a>
        </li>
        <li><a href="#tabs-3">Tab 3</a>
        </li>
    </ul>
    <div id="tabs-1">
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
    </div>
    <div id="tabs-2">
        <asp:Button ID="Button2" runat="server" Text="Submit" OnClick="Button2_Click" style="height: 26px" />
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
        </asp:DropDownList>
    </div>
    <div id="tabs-3">
        <asp:Button ID="Button3" runat="server" Text="Submit" OnClick="Button3_Click" />
    </div>
</div>

我遵循不同的链接,但在回发后它保留到tab1但不保留tab2

1 个答案:

答案 0 :(得分:0)

最简单的方法来创建自定义查询并读取查询字符串..根据查询字符串值打开该特定选项卡。

  

用于提取查询字符串值的JavaScript函数:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
  

示例:

    http://asp.net?tab=2
      var qstr = getParameterByName('tab');   
       if(qstr=='2')
        ...Opne particular tab   Or make it dynamic