如何使用jQuery重定向到特定选项卡 [英] How to redirect to a specific tab using jquery

查看:85
本文介绍了如何使用jQuery重定向到特定选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <script>   $(function() {
           $( "#tabs" ).tabs();   });   
    </script>

    <div id="tabs">
       <ul>
           <li><a href="#tabs-1">tab1</a></li>
           <li><a href="#tabs-2">tab2</a></li>
           <li><a href="#tabs-3">tab3</a></li>   
      </ul> 
      
    <div id="tabs-1">   
    </div>   
    <div id="tabs-2">   
    </div>   
    <div id="tabs-3">   
    </div>

    </div>

<div id="tabs">
       <ul>
           <li><a href="#tabs-1">Reg</a></li>
           <li><a href="#tabs-2">Summery</a></li>
           <li><a href="#tabs-3">Advanced Search</a></li>   
      </ul> 
      
<div id="tabs-1">   
</div>   
<div id="tabs-2">   
</div>   
<div id="tabs-3">
  <table style="width: 100%;">
                            <tr>
                                <td>
                                    Company:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlCompanies" runat="server" CssClass="dropdown" Width="250px">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    <asp:Button ID="btnSearchTotal" runat="server" OnClick="btnSearchTotal_Click" Text="Search"
                                        Width="100px" CssClass="greenbutton" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:GridView ID="gdvAuthorize" runat="server" AutoGenerateColumns="False" Width="777px"
                                        OnRowCommand="gdvAuthorize_RowCommand" OnRowEditing="gdvAuthorize_RowEditing"
                                        CssClass="mGrid">
                                        <Columns>
                                            <asp:BoundField DataField="SlipYear" HeaderText="Slip Year" />
                                            <asp:BoundField DataField="SlipMonthName" HeaderText="Slip Month" />
                                            <asp:BoundField DataField="SlipCategoryName" HeaderText="Slip Category Name"></asp:BoundField>
                                            <asp:BoundField DataField="TotalCount" HeaderText="Total Count" />
                                            <asp:ButtonField CommandName="SELECT" ImageUrl="~/images/icon_view.gif" ButtonType="Image">
                                                <ItemStyle Width="20px" />
                                            </asp:ButtonField>
                                            <asp:TemplateField HeaderText="SlipMonthID" Visible="False">
                                                <ItemTemplate>
                                                    <asp:Label ID="SlipMonth" runat="server" Text='<%# Bind("SlipMonth") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </td>
                            </tr>
                        </table>
                    </p>
                </div>
                <div id="tabs-2">
                    <p>
                        <table style="width: 100%;">
                            <tr>
                                <td>
                                    Company:
                                    <td>
                                        <asp:DropDownList ID="ddlCompany" runat="server" CssClass="dropdown" Width="250px">
                                        </asp:DropDownList>
                                    </td>
                            </tr>
                            <tr>
                                <td>
                                    Slip Category:
                                    <td>
                                        <asp:DropDownList ID="ddlSlipCategory" runat="server" CssClass="dropdown" Width="125px">
                                        </asp:DropDownList>
                                        <asp:Label ID="lblError1" runat="server" ForeColor="Red" Text="Select Category"></asp:Label>
                                    </td>
                            </tr>
                            <tr>
                                <td>
                                    Slip Year:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlSlipYear" runat="server" CssClass="dropdown" Width="125px">
                                    </asp:DropDownList>
                                    <asp:Label ID="lblError2" runat="server" ForeColor="Red" Text="Select Year"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Slip Month:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlSlipMonth" runat="server" CssClass="dropdown" Width="125px">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    <asp:Button ID="Button2" runat="server" CssClass="greenbutton" OnClick="btnSearch_Click"
                                        Text="Search" Width="100px" />
                                </td>
                            </tr>
                        </table>
                    </p>
                </div>
</table>

</div>

</div>

这是我目前用于标签功能的代码.在tab3内容中,我正在执行搜索功能并将搜索数据加载到数据网格视图中.但是当搜索功能选项卡中没有数据时,将自动重定向到选项卡1,如何保持留在tab3中而不重定向到选项卡1?

Here is the code that I'm currently using for tab function.In tab3 content i'm performing a search function and load search data to a data grid view.But when there is no data from the search function tab will automatically redirect to tab 1,How do I stay remain in tab3 without redirecting to the tab 1?

推荐答案

使用click方法.如果选项卡3上没有返回任何结果,请尝试:

Use the click method. If no results are returned on tab 3, try:

$('[href="#tabs-3"]').click();

无论结果如何,这都会返回两个选项卡3.

this will return you two tab 3 regardless of the results.

这篇关于如何使用jQuery重定向到特定选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆