手机端的 上拉加载列表更多(Java)

         刚来公司,觉得只是遇到的第一个难题。主要方法就是将数据从数据库取出来后,将这些数据以统一的格式放在在一个新的jsp页面中,再在住页面中通过js加载这个新的jsp页面,下面是代码:

       前端的js代码:

      <script type="text/javascript">
var k = true;
var w = $(window);
var curp = 2;
$("body").scrollTop(1);
var total=$('#totalpage').html();
if(total<=1){
$('#drag').hide();
   k = false;
}

//滚动到页面底部时,自动加载更多
window.addEventListener("scroll",function scrollHandler(){
//showImg();  //bblyy
var scrollh = $(document).height();
var bua = navigator.userAgent.toLowerCase();
if(bua.indexOf('iphone') != -1 || bua.indexOf('ios') != -1){
scrollh = scrollh-140;
}else{
scrollh = scrollh-80;
}
var c=document.documentElement.clientHeight || document.body.clientHeight, t=$(document).scrollTop();
if(k != false && ($(document).scrollTop() + w.height()) >= scrollh){
load();
}
},100); 

function load(){
var draginner=$('.draginner')[0];
var total=$('#totalpage').html();
k = false;
$('.draginner').css('padding-left','10px');
draginner.style.background="url(http://js.soufunimg.com/wireless_m/touch/img/load.gif) 0 50% no-repeat";
draginner.innerHTML="正在加载请稍候";
var phone = '${requestScope.phone==null?"":requestScope.phone}';//'${param.phone}'
var pagesize = '${requestScope.pagesize==null?"":requestScope.pagesize}';
//var pageindex = '${requestScope.pageindex==null?"":requestScope.pageindex}';
var pageindex = curp;
$.post('/user.d?m=addDecoration&phone='+phone+'&pagesize='+pagesize+'&pageindex='+pageindex,
function(data){ //这个data是个ModelAndView对象  
$('#content').append(data);
$('.draginner').css('padding-left','0px');
draginner.style.background="";
draginner.innerHTML="上拉自动加载更多";
curp=curp+1;
k = true;
if(curp>parseInt(total)){
$('#drag').hide();
k = false;
}
//showImg(); //bblyy
});
}

</script>

下面是body中的代码:

<body>
<jsp:include page="/jsgatongji.jsp"></jsp:include>
<jsp:include page="/newTopOfInfo.jsp"></jsp:include>
<div class="listBox pd10">
<div class="f16">您共有${requestScope.mydecorationList.totalCount}个装修请求</div>
    <ul class="list2 mt10" id="content">
    <c:if test="${requestScope.mydecorationList.totalCount==0}">       
        <div style="height:200px;">
        <div style="margin-top:100px;line-height:2em; text-align:center;"> 目前您暂无发标记录</div>
        </div>
    </c:if>
    <c:if test="${requestScope.mydecorationList.totalCount>0}">
       <c:forEach var="task" items="${requestScope.mydecorationList.taskList}">
          <li>
          <c:if test="${task.replyNum >0}">
             <a href="/user.d?m=reply&taskid=${task.taskID }">
          </c:if> 
        <div class="time f12 f999"><span>发标时间:${task.createTime }</span></div>
            <div class="introBox pd10">
             <c:if test="${task.replyNum>0 }">                                                                      
                   <div class="icon_m"></div>   
              </c:if>         
                <p class="f14">[${task.city }]${task.estateName}</p>
                <c:if test="${task.replyNum >0}">
                   <p class="f12 f999">已有${task.replyNum }人应答</p>
                </c:if> 
                <c:if test="${task.replyNum==0 }">
                    <p class="f12 f999">暂无人应答</p>
                </c:if>                        
            </div>
             <c:if test="${task.replyNum >0}">
                </a>
             </c:if> 
         </li>
       </c:forEach>
       </c:if>
    </ul>
</div>
<div id="totalpage" class="none">${requestScope.totalPage }</div>
<div id="drag" ><span style="color: red;"></span>
<div class="draginner fblu" style="height:37px;background:none;font-size:16px;" align="center" >上拉自动加载更多</div>
</div>

<jsp:include page="/foot.jsp"></jsp:include>


这里还要创建一个新的jsp页面,新的jsp页面中的代码和主jsp页面中的一部分代码是一样的,这个jsp页面的完整代码

<%@page language="java"  pageEncoding="GBK"  contentType="text/html;charset=GBK"%>
<%@page import="java.util.*"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions"%>
<%@page import="java.net.URLEncoder"%>
      <c:forEach var="task" items="${requestScope.mydecorationList.taskList}">
          <li>
          <c:if test="${task.replyNum >0}">
             <a href="/user.d?m=reply&taskid=${task.taskID }">
          </c:if> 
        <div class="time f12 f999"><span>发标时间:${task.createTime }</span></div>
            <div class="introBox pd10">
             <c:if test="${task.replyNum>0 }">                                                                      
                   <div class="icon_m"></div>   
              </c:if>         
                <p class="f14">[${task.city }]${task.estateName}</p>
                <c:if test="${task.replyNum >0}">
                   <p class="f12 f999">已有${task.replyNum }人应答</p>
                </c:if> 
                <c:if test="${task.replyNum==0 }">
                    <p class="f12 f999">暂无人应答</p>
                </c:if>                        
            </div>
             <c:if test="${task.replyNum >0}">
                </a>
             </c:if> 
         </li>
       </c:forEach>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值