81,091
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var currentPage=1; //当前第1页
var pageSize = 7; //每页7条数据
$(document).ready(function(){
getNewsData();
})
function getNewsData(){
$.ajax({
url:'listInfoAjax.action', //进入页面执行listInfoAjax action
data:'currentPage='+currentPage, //参数 当前页,默认为1
type:'post',
dataType:'json', //使用接送格式。
// json格式的struts配置为
//<package name="...." extends="json-default" >
// <action name="..." class="..." method="..." >
<result type="json"></result>
// </action>
//</package>
success:function(data){ //回调函数,如果后台方法没有抛异常,执行下面的语句块。
// totalCount ,pageSize,infos,后台方法里变量
totalCount=data.totalCount; //总记录数
totalPage=data.pageSize; //总页数
var inf=data.infos; //集合
$("#deleteall").empty(); //清空页面数据源
var html=""; 即将要插入的数据
$.each(inf,function(i,news){ //相当于for循环
//需要展示的内容,如id,title,date
var id=news.id;
var title=news.title;
var date=news.date;
html+="<tr><td><input type='checkbox' style='background: #f4f4f4;border: 0px;' value='"+id+"'></td> <td>"+date+"</td><td>"+title+"</td> </tr>" //插入的数据
})
$(html).appendTo("#deleteall"); 数据插入到deleteall里面
$("#crt").empty(); //清空当前页字符串
$("#crt").append(currentPage); //改变当前页字符串
$(".fenye1").unbind(); // 给上一页,下一页,解除bind
$("#deleteall tr").css("background","#e5e5e5"); //给数据添加样式
$("#deleteall tr").mouseover(function(){
$(this).css("background","#FFFFCC").siblings().css("background","#e5e5e5");//同上
})
//改变上一页,下一页,样式。以及传入的样式。
if(totalPage!=1){
if(currentPage==1){
$("#pre").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='syy'>上一页</b>");
$("#next").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else if(currentPage==totalPage){
$("#next").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='xyy'>下一页</b>");
$("#pre").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else{
$("#syy").replaceWith("<a id='pre' class='fenye1' href='#'>上一页</a>");
$("#xyy").replaceWith("<a id='next' class='fenye1' href='#'>下一页</a>");
$(".fenye1").click(function(){
changeCurrentPage($(this).attr("id"));
});
}
}
}
});
}
function changeCurrentPage(id){
if(id=="pre") currentPage -= 1;
else if(id=="next") currentPage += 1;
else currentPage = id;
getNewsData();
}
</script>
public List<?> list;
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
list = this.UserService.execSQLQuery(sql);
2.前台直接展示:
<s:iterator value="#request.list" id="str" >
<s:property value="#str[0]"/>
<s:property value="#str[1]"/>
</s:iterator>