doukuanyong1939 2017-02-17 05:52
浏览 50
已采纳

在php中显示一些记录后显示更多显示

Below is my script working fine for show more and show less. But please tell me how to show first three rows after that. I want to show the show more button.

The data is coming from foreach loop and in tabular format.
After x = 4, please tell me what to add so that it displays 3 rows of foreach. After that I want same script to work:

<script>
    $(document).ready(function () {
        x = 4;

        size_li = $("#Table td").size();

        //$('#Table tr').show(x);
        $('#td td:lt('+x+')').show();
        $('#loadMore').click(function () {
            x= (x+5 <= size_li) ? x+4 : size_li;
            $('#Table td:lt('+x+')').show();
        });
        $('#showLess').click(function () {
            x=(x-5<0) ? 5 : x-4;
            $('#Table td').not(':lt('+x+')').hide();
        });
    });
</script>
  • 写回答

1条回答 默认 最新

  • douti6740 2017-02-17 06:10
    关注

    Hope this works for you.. i made a little changes as i understand the problem.

    $(document).ready(function () {
     
     
     
     var table = $('#Table');
    for(i=0; i<8; i++){
        var row = $('<tr></tr>').addClass('bar').text('result ' + i);
        table.append(row);
    }
    
    table.find('tr:gt(2)').hide();
     
     x=3;
    
    var size_li = table.find("tr").size();
            
             $('tr:lt('+x+')').show();
            $('#loadMore').click(function () {
                x= (x+5 <= size_li) ? x+4 : size_li;
                $('#Table tr:lt('+x+')').show();
            });
            $('#showLess').click(function () {
                x=(x-5<0) ? 5 : x-4;
                $('#Table tr').not(':lt('+x+')').hide();
            });
        });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table id="Table">
    
    </table>
    
    <button id="loadMore">more</button>
    
    <button id="showLess">less</button>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线