2009-02-24 55 views

回答

6

如果您正在尋找光代碼,完全跳過jQuery和使用純HTML/CSS:

<table> 
    <thead> 
     <tr><th>Header Item 1</th><th>Header Item 2</th></tr> 
    </thead> 
    <tfoot> 
     <tr><th>Footer Item 1</th><th>Footer Item 2</th></tr> 
    </tfoot> 
    <tbody style="overflow-y: scroll; overflow-x: hidden; height: 100px;"> 
     <tr><td>Item 1-1</td><td>Item 2-1</td></tr> 
     ... 
     <tr><td>Item 1-N</td><td>Item 2-N</td></tr> 
    </tbody> 
</table> 

的關鍵是在設置在TBODY溢出CSS,從而使該部分滾動(但不是整個表格)。您還需要設置高度,以便可以定義可滾動部分的高度。

+0

哦!很酷,這將做到這一點。 謝謝 – Saneef 2009-02-24 19:18:54

+4

請記住,這不是一個「跨瀏覽器」兼容的解決方案。這不適用於Internet Explorer 7或更低版​​本或Safari。 – James 2009-02-24 21:00:13