jquery选项卡 - 将内容从包含的jsp切换到另一个

时间:2012-03-31 15:08:42

标签: javascript jquery jsp

我有一个带有jquery选项卡的主页面。我的标签内容是我包含的jsp页面:

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Users</a></li>
    </ul>
    <div id="tabs-1"> <jsp:include page="users.jsp" /> </div>
</div>

此jsp页面包含一个显示用户详细信息的表。这是表格的标题: 我希望最后一列包含一个“详细信息”链接,当它被点击时 - 我想 将选项卡的内容更改为显示用户详细信息的其他jsp页面。

几个问题:

  1. 如何在点击时切换到第二个jsp?
  2. 为了呈现所请求用户的详细信息,我需要以某种方式将userID传递给第二个jsp页面。我该怎么做?我有一个链接,它的id是我需要的userId:

    <td><a id="<%=user.getUserID()%>">Details</a></td>
    
  3. 我真的很擅长这个问题,尝试过我的问题,但我无法将它们全部拼凑成一个有效的解决方案。

    谢谢!

    观看来源:

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Conf4You</title>
    <link type="text/css" href="css/cupertino/jquery-ui-1.8.18.custom.css"
    
        rel="stylesheet" />
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function() {
            $('#tabs').tabs();
        });
    
    </script>
    <style type="text/css">
    /*demo page css*/
    
    body {
        font: 62.5% "Trebuchet MS", sans-serif;
        margin: 50px;
    }
    
    .demoHeaders {
        margin-top: 2em;
    }
    </style>
    </head>
    <body>
    <!-- Tabs -->
    <h2 class="demoHeaders">Tabs</h2>
    <div id="tabs">
    <ul>
      <li><a href="#tabs-1">Users</a></li>
    </ul>
    <div id="tabs-1">
    
    
    
    
    
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <link type="text/css" href="css/main.css" rel="stylesheet" />
    <link type="text/css" href="css/tables/tableList.css" rel="stylesheet" />
    </head>
    <body>
    <p class="horizontal-line">Actions</p>
    <p class="horizontal-line">Users</p>
    <table cellpadding="0" cellspacing="0" border="0" id="table" class="sortable">
      <thead>
        <tr>
          <th><h3>Name</h3></th>
          <th><h3>Phone 1</h3></th>
          <th><h3>Phone 2</h3></th>
          <th><h3>Email</h3></th>
          <th><h3>Company</h3></th>
          <th><h3>Last Access</h3></th>
          <th class="nosort"><h3>Details</h3></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>user0</td>
          <td>Num10</td>
          <td>num20</td>
          <td><a style="color: blue;" href="mailto:yada0@gmail.com">yada0@gmail.com</a></td>
          <td>yada</td>
          <td>31-03-2012 06:32:34 PM</td>
          <td><a id="1" onclick="detailsAction()"
    
                        style="color: blue;">Details</a></td>
          <!-- todo- change details link -->
        </tr>
        <tr>
          <td>user1</td>
          <td>Num11</td>
          <td>num21</td>
          <td><a style="color: blue;" href="mailto:yada1@gmail.com">yada1@gmail.com</a></td>
          <td>yada</td>
          <td>31-03-2012 06:32:34 PM</td>
          <td><a id="2" onclick="detailsAction()"
    
                        style="color: blue;">Details</a></td>
          <!-- todo- change details link -->
        </tr>
        <tr>
          <td>user2</td>
          <td>Num12</td>
          <td>num22</td>
          <td><a style="color: blue;" href="mailto:yada2@gmail.com">yada2@gmail.com</a></td>
          <td>yada</td>
          <td>31-03-2012 06:32:34 PM</td>
          <td><a id="3" onclick="detailsAction()"
    
                        style="color: blue;">Details</a></td>
          <!-- todo- change details link -->
        </tr>
        <tr>
          <td>user3</td>
          <td>Num13</td>
          <td>num23</td>
          <td><a style="color: blue;" href="mailto:yada3@gmail.com">yada3@gmail.com</a></td>
          <td>yada</td>
          <td>31-03-2012 06:32:34 PM</td>
          <td><a id="4" onclick="detailsAction()"
    
                        style="color: blue;">Details</a></td>
          <!-- todo- change details link -->
        </tr>
        <tr>
          <td>user4</td>
          <td>Num14</td>
          <td>num24</td>
          <td><a style="color: blue;" href="mailto:yada4@gmail.com">yada4@gmail.com</a></td>
          <td>yada</td>
          <td>31-03-2012 06:32:34 PM</td>
          <td><a id="5" onclick="detailsAction()"
    
                        style="color: blue;">Details</a></td>
          <!-- todo- change details link -->
        </tr>
      </tbody>
    </table>
    <div id="controls">
      <div id="perpage">
        <select onchange="sorter.size(this.value)">
          <option value="5">5</option>
          <option value="10" selected="selected">10</option>
          <option value="20">20</option>
          <option value="50">50</option>
          <option value="100">100</option>
        </select>
        <span>Entries Per Page</span> </div>
      <div id="navigation"> <img src="css/tables/images/first.gif" width="16" height="16"
    
                    alt="First Page" onclick="sorter.move(-1,true)" /> <img
    
                    src="css/tables/images/previous.gif" width="16" height="16"
    
                    alt="First Page" onclick="sorter.move(-1)" /> <img
    
                    src="css/tables/images/next.gif" width="16" height="16"
    
                    alt="First Page" onclick="sorter.move(1)" /> <img
    
                    src="css/tables/images/last.gif" width="16" height="16"
    
                    alt="Last Page" onclick="sorter.move(1,true)" /> </div>
      <div id="text"> Displaying Page <span id="currentpage"></span> of <span
    
                    id="pagelimit"></span> </div>
    </div>
    <script type="text/javascript" src="js/tables/script.js"></script>
    <script type="text/javascript">
    
            var sorter = new TINY.table.sorter("sorter");
    
            sorter.head = "head";
    
            sorter.asc = "asc";
    
            sorter.desc = "desc";
    
            sorter.even = "evenrow";
    
            sorter.odd = "oddrow";
    
            sorter.evensel = "evenselected";
    
            sorter.oddsel = "oddselected";
    
            sorter.paginate = true;
    
            sorter.currentid = "currentpage";
    
            sorter.limitid = "pagelimit";
    
            sorter.init("table", 1);
    
        </script>
    </body>
    </html>
    </div>
    </div>
    </body>
    </html>
    

2 个答案:

答案 0 :(得分:1)

找到解决方案,这应该是脚本:

 <script type="text/javascript">

$(document).ready(function() {
    $('#tabs').tabs({
        load: function(event, ui) {
            $(ui.panel).delegate('a', 'click', function(event) {
                $(ui.panel).load(this.href);
                event.preventDefault();
            });
        }
    });

    $("#tabs").bind('tabsselect', function(event, ui) {
        window.location.href=ui.tab;
    });

});

</script>

使用它:

<div id="tabs">
        <ul>
            <li><a href="users.jsp"><span>Users</span></a></li>
            <li><a href="conference.jsp"><span>Conferences</span></a></li>
            <li><a href="companies.jsp"><span>Companies</span></a></li>
        </ul>
</div>

这就是为什么第一个标签的内容是users.jsp。在usrs.jsp中我使用链接:

<td><a href="userDetails.jsp?userid=<%=user.getUserName()%>"> <img src="/conf4u/resources/imgs/yada.png" alt=""> Details </a> </td>

和userDetails.jsp现在在单击时在同一个选项卡中打开。

答案 1 :(得分:0)

您可以将正确的网址放入标签锚点的href中,以允许加载标签的ajax。

请参阅ajax loading示例:http://jqueryui.com/demos/tabs/#ajax