搜尋
首頁後端開發php教程javascript - 自己研究的分頁,感覺ajax這裡寫的不太好,如何改進;

<code>


    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="page.css">

<style>
    *{
        padding: 0px;
        margin: 0px;
    }
    *{ margin:0; padding:0; list-style:none;}
    a{ text-decoration:none;}
    a:hover{ text-decoration:none;}
    .tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;}
    .tcdPageCode a{display: inline-block;color: #428bca;display: inline-block;height: 25px;
    line-height: 25px;    padding: 0 10px;border: 1px solid #ddd;    margin: 0 2px;border-radius: 4px;vertical-align: middle;}
    .tcdPageCode a:hover{text-decoration: none;border: 1px solid #428bca;}
    .tcdPageCode span.current{display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;
    margin: 0 2px;color: #fff;background-color: #428bca;    border: 1px solid #428bca;border-radius: 4px;vertical-align: middle;}
    .tcdPageCode span.disabled{    display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;
    margin: 0 2px;    color: #bfbfbf;background: #f2f2f2;border: 1px solid #bfbfbf;border-radius: 4px;vertical-align: middle;}
    ul{
        list-style: none;
    }
    .wrap >ul > li{
        width: 250px;
        height: 350px;
        margin: 20px;
        /*border: 1px green solid;*/
        float: left;
        margin-bottom: 40px;
    }
    .wrap >ul > li>img{
        width: 100%;
        height: 100%;
    }
    .wrap >ul > li>p{
        text-align: center;
        line-height: 30px;
        height: 30px;
    }
    .wrap{
        margin: 100px auto;
        border: 1px solid red;
        height: 1800px;
        width: 1460px;
    }
</style>

  <div class="wrap">
       <ul class="movieList">
           <!--<li>-->
               <!--<img src="/static/imghwm/default1.png"  data-src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"  class="lazy" alt="">-->
               <!--<p>电影名:惊天魔盗团</p>-->
           <!--</li>-->
       </ul>
      <!-- 代码部分begin -->
      <div class="tcdPageCode">
      </div>
  </div>


<script></script>
<script src="http://www.lanrenzhijia.com/ajaxjs/jquery.page.js"></script>

<script>
    $(function () {
       //初始化第一页数据;
        var urlApi = 'http://api.douban.com/v2/movie/top250'
        $.ajax({
            url:urlApi,
            type:'get',
            dataType:'jsonp',
            data:{
                //从第几条开始请求;
                "start" : 0,
                //请求多少条数据
                "count" : 10
            },
            success:function(data){
            //total总条数属性,计算总页数;
            var total = parseInt(data.total/10);
                result  = data.subjects;
                var str='';
                for(var i=0;i<result.length;i++){
                    var item = result[i];
                    str += '<li><img src="'+item.images.large
                            +'" alt=""><p>'+item.title+''
                }
                //追加渲染到页面
                $('.movieList').append(str)
                //分页插件,
                $(".tcdPageCode").createPage({
                    //pageCount:总页数
                    pageCount:total,
                    //current:当前页
                    current:1,
                    backFn:function(pageIndex){
                    //单击回调方法,pageIndex是当前页码
                        $(".movieList").empty();
                        var start = 10*pageIndex;
                        $.ajax({
                            url:urlApi,
                            type:'get',
                            dataType:'jsonp',
                            data:{
                                "start" : start,
                                "count" : 10,
                            },
                            success:function(data){
                                var result  = data.subjects;
                                var str='';
                                for(var i=0;i<result.length;i++){
                                    var item = result[i];
                                    str += '<li><img src="'+item.images.large
                                            +'" alt=""><p>'+item.title+''
                                }
                                $('.movieList').append(str)
                            }
                        })
                    }
                });
            }
        })
    })
</script></code>

回覆內容:

<code>


    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="page.css">

<style>
    *{
        padding: 0px;
        margin: 0px;
    }
    *{ margin:0; padding:0; list-style:none;}
    a{ text-decoration:none;}
    a:hover{ text-decoration:none;}
    .tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;}
    .tcdPageCode a{display: inline-block;color: #428bca;display: inline-block;height: 25px;
    line-height: 25px;    padding: 0 10px;border: 1px solid #ddd;    margin: 0 2px;border-radius: 4px;vertical-align: middle;}
    .tcdPageCode a:hover{text-decoration: none;border: 1px solid #428bca;}
    .tcdPageCode span.current{display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;
    margin: 0 2px;color: #fff;background-color: #428bca;    border: 1px solid #428bca;border-radius: 4px;vertical-align: middle;}
    .tcdPageCode span.disabled{    display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;
    margin: 0 2px;    color: #bfbfbf;background: #f2f2f2;border: 1px solid #bfbfbf;border-radius: 4px;vertical-align: middle;}
    ul{
        list-style: none;
    }
    .wrap >ul > li{
        width: 250px;
        height: 350px;
        margin: 20px;
        /*border: 1px green solid;*/
        float: left;
        margin-bottom: 40px;
    }
    .wrap >ul > li>img{
        width: 100%;
        height: 100%;
    }
    .wrap >ul > li>p{
        text-align: center;
        line-height: 30px;
        height: 30px;
    }
    .wrap{
        margin: 100px auto;
        border: 1px solid red;
        height: 1800px;
        width: 1460px;
    }
</style>

  <div class="wrap">
       <ul class="movieList">
           <!--<li>-->
               <!--<img src="/static/imghwm/default1.png"  data-src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"  class="lazy" alt="">-->
               <!--<p>电影名:惊天魔盗团</p>-->
           <!--</li>-->
       </ul>
      <!-- 代码部分begin -->
      <div class="tcdPageCode">
      </div>
  </div>


<script></script>
<script src="http://www.lanrenzhijia.com/ajaxjs/jquery.page.js"></script>

<script>
    $(function () {
       //初始化第一页数据;
        var urlApi = 'http://api.douban.com/v2/movie/top250'
        $.ajax({
            url:urlApi,
            type:'get',
            dataType:'jsonp',
            data:{
                //从第几条开始请求;
                "start" : 0,
                //请求多少条数据
                "count" : 10
            },
            success:function(data){
            //total总条数属性,计算总页数;
            var total = parseInt(data.total/10);
                result  = data.subjects;
                var str='';
                for(var i=0;i<result.length;i++){
                    var item = result[i];
                    str += '<li><img src="'+item.images.large
                            +'" alt=""><p>'+item.title+''
                }
                //追加渲染到页面
                $('.movieList').append(str)
                //分页插件,
                $(".tcdPageCode").createPage({
                    //pageCount:总页数
                    pageCount:total,
                    //current:当前页
                    current:1,
                    backFn:function(pageIndex){
                    //单击回调方法,pageIndex是当前页码
                        $(".movieList").empty();
                        var start = 10*pageIndex;
                        $.ajax({
                            url:urlApi,
                            type:'get',
                            dataType:'jsonp',
                            data:{
                                "start" : start,
                                "count" : 10,
                            },
                            success:function(data){
                                var result  = data.subjects;
                                var str='';
                                for(var i=0;i<result.length;i++){
                                    var item = result[i];
                                    str += '<li><img src="'+item.images.large
                                            +'" alt=""><p>'+item.title+''
                                }
                                $('.movieList').append(str)
                            }
                        })
                    }
                });
            }
        })
    })
</script></code>

你可以自己寫個jquery的分頁插件,我自己寫過一個很簡單的...

地址在這裡,https://github.com/luoyjx/jqu...

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何使PHP應用程序更快如何使PHP應用程序更快May 12, 2025 am 12:12 AM

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

PHP性能優化清單:立即提高速度PHP性能優化清單:立即提高速度May 12, 2025 am 12:07 AM

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

PHP依賴注入:提高代碼可檢驗性PHP依賴注入:提高代碼可檢驗性May 12, 2025 am 12:03 AM

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

PHP性能優化:數據庫查詢優化PHP性能優化:數據庫查詢優化May 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

簡單指南:帶有PHP腳本的電子郵件發送簡單指南:帶有PHP腳本的電子郵件發送May 12, 2025 am 12:02 AM

phpisusedforsenderemailsduetoitsbuilt-inmail()函數andsupportivelibrariesLikePhpMailerAndSwiftMailer.1)usethemail()functionForbasiceMails,butithasimails.2)butithasimail.2)

PHP性能:識別和修復瓶頸PHP性能:識別和修復瓶頸May 11, 2025 am 12:13 AM

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显著提升PHP应用的性能。

PHP的依賴注入:快速摘要PHP的依賴注入:快速摘要May 11, 2025 am 12:09 AM

依賴性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增強量強制性,可驗證性和MATIALWINABIOS.ItallowSpasspassingDepentenciesLikEdenciesLikedAbaseConnectionStoclasseconnectionStoclasseSasasasasareTers,interitationAseTestingEaseTestingEaseTestingEaseTestingEasingAndScalability。

提高PHP性能:緩存策略和技術提高PHP性能:緩存策略和技術May 11, 2025 am 12:08 AM

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具