2012-01-31 107 views
1

我有一个动态填充的jquery scorlling表。我正在使用Bob Craven's jquery scroll solution有一个滚动表,想要在滚动的底部开始?

我想要的是当页面加载表时应该在底部,也是当一个新的行被动态添加时,这应该是重点所在。

脚本后它被应用创建围着桌子div的...这是源代码:

<div style="overflow: hidden; display: inline-block; border: 0px solid rgb(136, 136, 136);" id="placeordetb_table_wrap"> 
<div style="width: 100%; overflow: hidden;" id="placeordetb_head_wrap"> 
<table style="table-layout: fixed;" class="placeorder_items" id="placeordetb_head" border="0" cellpadding="0" cellspacing="0" width="100%"> 
</table> 
</div> 
<div style="width: 100%; height: 160px; overflow: auto;" id="placeordetb_body_wrap">      <table class="placeorder_items" id="placeordetb" border="0" cellpadding="0" cellspacing="0" width="100%"> 
    <tbody> 
     <tr valign="top">  
     <th>Line number</th> 
     <th>Notes</th> 
     <th>Profile</th> 
     <th>Inner</th> 
     <th>Outer</th> 
     <th>Length</th> 
     <th>Unit</th> 
     <th>Qty</th> 
     <th>Line Value (Net)</th> 
     <th></th> 
     </tr> 
     <tr id="10"> 
     <td>10</td> 
     <td style="text-align: center;"></td> 
     <td></td><td></td><td></td><td></td><td>6.5</td><td>1</td> 
     <td></td> 
     <td><a href="javascript:deleteRow(1029,10)">Delete</a></td></tr> 
     </tbody> 
</table> 
</div></div> 

正常:

<div class="placeorder_item"> 

<table width="100%" cellpadding="0" cellspacing="0" border="0" class="placeorder_items" id = "placeordetb" > 
<tr valign="top"> 
<th>Line number</th> 
<th>Notes</th> 
<th>Profile</th> 
<th>Inner</th> 
<th>Outer</th> 
<th>Length</th> 
<th>Unit</th> 
<th>Qty</th> 
<th>Line Value (Net)</th> 
<th></th> 
</tr> 

<tr id="10" > 
<td>10&nbsp;</td> 
<td style="text-align:center;"> 
    </td> 
<td>etc010&nbsp;</td> 
<td>1002M&nbsp;</td> 
<td>1003&nbsp;</td> 
<td>6.500 &nbsp;</td> 
<td>L6.5&nbsp;</td> 
<td>1&nbsp;</td> 
<td>62.52&nbsp;</td> 

删除

回答

2

使用jQuery的.scrollTop()方法动态处理滚动:

$(document).ready(function(){ 
    var scrollBottom = Math.max($('#placeordetb').height() - $('#placeordetb_body_wrap').height(), 0); 
    $('#placeordetb_body_wrap').scrollTop(scrollBottom); 
}); 

例如,请参阅以下jsFiddle

+0

任何错误被抛出?检查演示的更新答案。 – 2012-01-31 11:21:49

+0

没有错误没有任何东西 – Beginner 2012-01-31 11:26:30

+0

演示是否适用于您,至少?不幸的是,我只能使用你提供的HTML来工作,并不知道它为什么不能在页面中工作。是否有工作副本的公用URL,可以附加到您的问题上? – 2012-01-31 11:41:19