JSP中的可滚动表

时间:2017-03-19 13:46:51

标签: java css jsp

我面临在JSP中创建可滚动表(带有固定头)的问题。请帮忙。如果您需要什么,请告诉我

<div class = "scrollable">
 <table class = "table table-condensed table-hover">
    <thead>
    <tr class= "info">
        <th>Prod id</th>
        <th>Name </th>
        <th>Manufacturer</th>
        <th>Quantity</th>
        <th>Purchased Price</th>
        <th>Selling Price</th>
        <th>Weight/Packet</th>
        <th>Type</th>
        <th>Category</th>
     </tr>
     </thead>
     <tbody >
    <%  while(rs.next()){ %>

    <tr class = "default">

    <td><%= rs.getString(1) %></td>
    <td><%= rs.getString(2) %> </td>
    <td><%= rs.getString(3) %></td> 
    <td><%= rs.getString(4) %></td>
    <td><%= rs.getString(5) %> </td>
    <td><%= rs.getString(6) %> </td>
    <td><%= rs.getString(7) %> </td>
    <td><%= rs.getString(8) %> </td>
    <td><%= rs.getString(9) %> </td>

    </tr>
    </tbody>
    <% } %>
    </table>
 </div>

哪里&#34; rs&#34;是结果集

1 个答案:

答案 0 :(得分:0)

试试这个,它会起作用。

&#13;
&#13;
// Change the selector if needed
var $table = $('table.scroll'),
    $bodyCells = $table.find('tbody tr:first').children(),
    colWidth;

// Adjust the width of thead cells when window resizes
$(window).resize(function() {
    // Get the tbody columns width array
    colWidth = $bodyCells.map(function() {
        return $(this).width();
    }).get();
    
    // Set the width of thead columns
    $table.find('thead tr').children().each(function(i, v) {
        $(v).width(colWidth[i]);
    });    
}).resize(); // Trigger resize handler
&#13;
table.scroll {
    width: 100%; /* Optional */
    /* border-collapse: collapse; */
    border-spacing: 0;
    border: 2px solid black;
}

table.scroll tbody,
table.scroll thead { display: block; }

thead tr th { 
    height: 30px;
    line-height: 30px;
    /*text-align: left;*/
}

table.scroll tbody {
    height: 100px;
    overflow-y: auto;
    overflow-x: hidden;
}

tbody { border-top: 2px solid black; }

tbody td, thead th {
    width: 20%; /* Optional */
    border-right: 1px solid black;
}

tbody td:last-child, thead th:last-child {
    border-right: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<table class="scroll">
    <thead>
        <tr>
            <th>Head 1</th>
            <th>Head 2</th>
            <th>Head 3</th>
            <th>Head 4</th>
            <th>Head 5</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Lorem ipsum dolor sit amet.</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
    </tbody>
</table>
&#13;
&#13;
&#13;