无线加载数据(点击)_编程笔记

无线加载数据(点击)

2024-09-29 08:18:58  浏览:146  作者:保利尼奥
{% if showpage!="" %} <div class="xypg-pagination-x12"> <div class="text-center"> <a href="javascript:void(0)" class="...
{% if showpage!="" %}
<div class="xypg-pagination-x12">
    <div class="text-center">
        <a href="javascript:void(0)" class="more-news text-center" data-page="2">点击浏览更多<i class="fa fa-long-arrow-right text-big margin-big-left"></i></a>
    </div>
</div>
{% endif %}

<script>var HOME_URL = "{{ url_index }}"</script>


{% if first_cid == 0 %}

<script>
    $(".more-news").click(function(){
        var page = $(this).attr("data-page");
        var cid = '{{ first_cid }}';
        var moreNewsButton = $(this);
        
        $.post(HOME_URL + "ajaxNews.php", {page: page,cid: cid}, function(data){
            
            if (data.length > 0) {
                var string = "";
                for (var i = 0; i < data.length; i++) {
                    // 将Unix时间戳转换为日期时间字符串
                    var timestamp = data[i].timeline;
                    var date = new Date(timestamp * 1000); // 转换为毫秒
                    var formattedDateTime =
                        date.getFullYear() + '-' +
                        String(date.getMonth() + 1).padStart(2, '0') + '-' +
                        String(date.getDate()).padStart(2, '0')  ;

                    string += "<div class='list-news2'>";
                    string += "<a href='"+data[i].url+"' title='"+data[i].title+"' class='clearfix'>";
                    string += "<div class='wz fl'>"+data[i].title+"</div>";
                    string += "<span>"+formattedDateTime+"</span>";
                    string += "</a></div>";
                }
                page = Number(page) + 1;
                $(".more-news").attr("data-page", page);
                $(".xypg_pplist").append(string);
                
            }else {
                moreNewsButton.text("没有了呢!");
                moreNewsButton.prop("disabled", true); 
            }

        })
    })

</script>

{% else %}

<script>
    $(".more-news").click(function(){
        var page = $(this).attr("data-page");
        var cid = '{{ first_cid }}';
        var moreNewsButton = $(this);
        
        $.post(HOME_URL + "ajaxNews.php", {page: page,cid: cid}, function(data){

            if (data.length > 0) {
                var string = "";
                for (var i = 0; i < data.length; i++) {
                    // 将Unix时间戳转换为日期时间字符串
                    var timestamp = data[i].timeline;
                    var date = new Date(timestamp * 1000); // 转换为毫秒
                    var formattedDateTime =
                        date.getFullYear() + '-' +
                        String(date.getMonth() + 1).padStart(2, '0') + '-' +
                        String(date.getDate()).padStart(2, '0')  ;

                    string += "<li>";
                    string += "<a href='"+data[i].url+"' title='"+data[i].title+"' class='flexf'>";
                    string += "<div class='img'><img src='"+data[i].uploadfiles+"' alt='"+data[i].title+"'></div>";
                    string += "<div class='det flexf'>";
                    string += "<div class='time'>";
                    string += "<div class='tm1'>"+String(date.getDate()).padStart(2, '0')+"</div>";
                    string += "<div class='tm2'>"+date.getFullYear() + '-' + String(date.getMonth() + 1).padStart(2, '0')+"</div>";
                    string += "</div>";
                    string += "<div class='nr flexf'>";
                    string += "<div class='det2'>";
                    string += "<div class='wz1'>"+data[i].title+"</div>";
                    string += "<div class='wz2'>"+data[i].summary.substring(0, 200)+"...</div>";
                    string += "</div>";
                    string += "<div class='button radius-none text-center'><i class='iconfont icon-jiantou_xiangyou_o font26'></i></div>";
                    string += "</div>";
                    string += "</div>";
                    string += "</a>";
                    string += "</li>";
                }
                page = Number(page) + 1;
                $(".more-news").attr("data-page", page);
                $(".xypg_pplist2").append(string);
                
            }else {
                moreNewsButton.text("没有了呢!");
                moreNewsButton.prop("disabled", true); 
            }

        })
    })

    // 缩略图
    function thumb(img){
        return "{{ app('content').thumb('"+data[i].uploadfiles+"', 800 , 800) }}";
    }

</script>

{% endif %}


上一篇:Navicat16.1直接激活.zip

下一篇:已经是最后一篇

评论区

共 0 条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

【随机内容】

返回顶部