刚刚学习前端的时候,需要一个无刷新的分页功能,找了一个不错的,大家也有很大分享,在这里写一个自己的部分代码,前后端都有,需要的小伙伴可以参考一下,代码不是完整的。
直接上伪代码<样式代码省略,部分js省略,不明白配置请参考次博客-》http://blog.csdn.net/starfd/article/details/25292019>
<tc_extend name="Public:common"/>
<block name="title"><title>{$title}</title></block>
<block name="JS">
</block>
<block name="content">
<!-- banner -->
<div class="banner"></div><div class="shadow"></div>
<div id="content_2">
<div class="side">
<h3>公告</h3>
<ul class="aside-list" id="oncl">
<li class="cur">公告</li>
<li>行业新闻</li>
</ul>
</div>
<div id="cut">
<div class="list-con" style="display:block ">
<ul class="new_list" id='page'>
<volist name="newslist" id ="news">
<li>
<!--新闻-->
<a href="{:U('Index/newsList',array('id'=>$news['id']))}" class="news">
<if condition="empty($news['smeta'] eq false)">
<img src="__UPLOAD__{$news['smeta']}">
</if>
<h4>{$news['post_title']}</h4>
<p>{$news['post_excerpt']}</p>
<span>{$news['post_modified']}</span>
</a>
<!--end-->
</li>
</volist>
</ul>
<div class="clear"></div>
<div class="pagging">
<div class="tcdPageCode"></div>
</div>
</div>
</div>
</div> <div class="clear"></div> </block>
<block name="FJS"> <script src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"></script>
<script src="http://www.lanrenzhijia.com/ajaxjs/jquery.page.js"></script>
<script>
$(".tcdPageCode").createPage({
pageCount:{$count},
current:1,
backFn:function(p){
$.ajax({
type:'post',
url:'index/getPage',
data:'p='+p,
dataType:'json',
success:function(data){
$("#page").html(data.info); //此处在后台拼接html内容
}
});
}
});
</script> <script>
$("#oncl li").click(function(){
$("#oncl li").eq($(this).index()).addClass("cur").siblings().removeClass('cur');
$(".list-con").hide().eq($(this).index()).show();
});
</script>
</block>
=====================我是分割线=============================
后台拼接html<此处使用的是thinkcmf框架,部分代码省略>
public function getPage() { $listRows = 4;
$count = 0;
$currentpage = empty($_POST['p'])? 1:$_POST['p'];
$goods_data = $this->_getNewList($listRows, $currentpage,$count);
$html = "";
foreach ($goods_data as $v) {
$html .=" <li><a href='";
$param = array('id'=>$v['id']);
$html .= "{:U('Index/newsList',{$param})}";
$html .= "class='news'>";
if(!empty($v['smeta'])){
$html .= "<img src='__UPLOAD__{$v['smeta']}'>";
}
$html .= "<h4>{$v['post_title']}</h4>";
$html .= "<p>{$v['post_excerpt']}</p>";
$html .= "<span>{$v['post_modified']}</span>";
$html .="</a></li>";
} $data = array('info'=>$html);
$this->ajaxReturn($data);
}