• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

javascript – 自己研究的分页,感觉ajax这里写的不太好,如何改进;

php 搞代码 3年前 (2022-01-23) 18次浏览 已收录 0个评论
文章目录[隐藏]
<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><body>  <div class='wrap'>       <ul class='movieList'>           <!---ecms <li>-->               <!---ecms -->               <!---ecms <p>电影名:惊天魔盗团</p>-->           <!---ecms </li>-->       </ul>      <!---ecms  代码部分begin -->      <div class="tcdPageCode">      </div>  </div><script src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"></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><p>'+item.title+'</p></li>'                }                //追加渲染到页面                $('.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><p>'+item.title+'</p></li>'                                }                                $('.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: #c<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>cc;}    .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><body>  <div class='wrap'>       <ul class='movieList'>           <!---ecms <li>-->               <!---ecms -->               <!---ecms <p>电影名:惊天魔盗团</p>-->           <!---ecms </li>-->       </ul>      <!---ecms  代码部分begin -->      <div class="tcdPageCode">      </div>  </div><script src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"></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><p>'+item.title+'</p></li>'                }                //追加渲染到页面                $('.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><p>'+item.title+'</p></li>'                                }                                $('.movieList').append(str)                            }                        })                    }                });            }        })    })</script></code>

你可以自己写个jquery的分页插件,我自己写过一个很简单的…

地址在这里,https://github.com/luoyjx/jqu…


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:javascript – 自己研究的分页,感觉ajax这里写的不太好,如何改进;
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址