一次一张幻灯片表

时间:2015-02-17 08:11:52

标签: javascript jquery html-table rows slideup

有人可以告诉我如何一次滑动一行吗?我一直在搜索代码以一次性翻转所有第一行,但我不明白我是如何使用for循环,但它只滑动第一行但它没有继续滑动直到最后一行我的桌子......

HTML

<table id='phoenix' border='0' cellpadding='0'>
    <tr style='background-color:lightgray;'>
        <th colspan='3' style='font-weight:bold;'>PHOENIX BOOKS</th>
            <tr>
            <tr>
                <th style='position:relative;width:20%;'>Item Code</th>
                <th style='position:relative;width:45%;'>Description</th>
                <th style='position:relative;width:20%;'>Stocks</th>
            </tr>
            <?php
                $serverName="PPHSQL01";
                $conInfo=array("Database"=>"Perks","UID"=>"sa","PWD"=>"asdasd");
                $con= sqlsrv_connect($serverName,$conInfo);

                $sql= sqlsrv_query($con,"Select A.WarehouseID,A.TitleID,A.CurrentBalance,B.TitleID,B.TitleCode,B.Title from dbo.vw_StocksBalances as A inner join dbo.Title as B on A.TitleID=B.TitleID where A.WarehouseID='5' ORDER BY A.CurrentBalance DESC");
                while($row=sqlsrv_fetch_array($sql))
                {
                    echo"<tr style='border-top:1px solid lightgray;'>";
                            echo"<td style='text-align:center;'>" .$row['TitleCode']. "</td>";
                            echo"<td>" .$row['Title']. "</td>";
                            echo"<td style='text-align:center;'>" .$row['CurrentBalance']. "</td>";
                    echo"</tr>";
                }
            ?>
</table>

的Javascript

var ros=$("table tr").length(); var i; for(i=0;i=ros;i++) { $("table tr:first").slideUp('slow'); }

1 个答案:

答案 0 :(得分:0)

这里看到每3秒停止工作的代码如果所有tr都在由mysql创建的表中向上滑动.. jsfiddle

HTML代码

<table style="width:100%">
  <tr>
  <td>Jill</td>
  <td>Smith</td> 
  <td>50</td>
 </tr>
<tr>
<td>Eve</td>
<td>Jackson</td> 
<td>94</td>
</tr>
<tr>
<td>Eve3</td>
<td>Jackson</td> 
<td>94</td>
</tr>
<tr>
<td>Eve4</td>
<td>Jackson</td> 
<td>94</td>
</tr>
 <tr>
 <td>Eve5</td>
 <td>Jackson</td> 
 <td>94</td>
 </tr>
  <tr>
  <td>Eve6</td>
  <td>Jackson</td> 
  <td>94</td>
 </tr>
  <tr>
   <td>Eve7</td>
   <td>Jackson</td> 
  <td>94</td>
  </tr>
  <tr>
    <td>Eve8</td>
     <td>Jackson</td> 
    <td>94</td>
   </tr>
 </table>

jquery代码:

 $(document).ready(function(){
   var counter = 2; 
   var length = ($('table tr').length)
    var timer =  setInterval(function(){
    if( length === counter){
      clearInterval(timer);
    }
    console.log(counter);  
    $('table tr:eq('+counter+')').slideUp(2000);
    counter++

    }, 3000);

 });