日期:2014-05-16 浏览次数:20374 次
function renderPaging(url,curPage,totalPage) { var pageBarNum = 5; var pageStr = ''; var gurl = function(num){ return url.replace('-page-',num); }; curPage = parseInt(curPage); totalPage = parseInt(totalPage); if(curPage > 1){ pageStr += '<span class="grey-12"><< <a class="paging-per" href="' + gurl(curPage-1) + '">上一页</a> </span>'; } var index = Math.floor(pageBarNum/2); var start = (curPage-index)>0 ? (curPage-index) : 1; var end = curPage + (pageBarNum-index); end = end<pageBarNum ? pageBarNum : end; if(start > 1){ pageStr += '<span class="grey-12"> <a class="paging-per" href="' + gurl(1) + '">1</a> </span>'; } if(start > 2){pageStr += '<span class="grey-12"> ... </span>';} for(var i=start; i<end; i++){ if(i>totalPage) break; if(i == curPage){ pageStr += '<span class="blue-12-bold"> <a class="paging-per paging-current" href="' + gurl(i) + '">' + i + '</a> </span>'; }else{ pageStr += '<span class="grey-12"> <a class="paging-per" href="' + gurl(i) + '">' + i + '</a> </span>'; } } if(end < totalPage){ pageStr += '<span class="grey-12"> ... </span>'; pageStr += '<span class="grey-12"> <a class="paging-per" href="' + gurl(totalPage) + '">' + totalPage + '</a> </span>'; } if(curPage < totalPage){ pageStr += '<span class="grey-12"> <a class="paging-per" href="' + gurl(curPage+1) + '">下一页</a> >></span>'; } return pageStr; }
?
?
后端只需要 传入 3个参数即可
$pager = array( 'pagecount' => ceil($counter / $numPerPage), 'url' => 'url.php/page/-page-' 'page' => $cur_page, ); $this->_view['pager'] = $pager;
?
demo:
<p id="pageBar" page="<?php echo $pager['page'];?>" pagecount="<?php echo $pager['pagecount'];?>" url="<?php echo $pager['url'];?>"></p>?
?
?
<?php /** * FAQ * * <sql> DROP TABLE IF EXISTS `product`; CREATE TABLE IF NOT EXISTS `product` ( `id` int(11) NOT NULL auto_increment, `name` varchar(64) collate utf8_unicode_ci NOT NULL, `describe` text, `image` varchar(120) NOT NULL default '', `undercarriage` tinyint(1) default '0', `is_newest` tinyint(1) default '0', `is_recommend` tinyint(1) default '0', `recommend_image` varchar(120) NOT NULL default '', `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL, PRIMARY KEY (`id`) )DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; * </sql> */ class ProductModel { public $tableName = 'product'; public $primaryKey = 'id'; public $nameField = 'name'; public $describeField = 'describe'; public $imageField = 'image'; /** * 下架字段 */ public $isUndercarriageField = 'undercarriage'; public $isNewField = 'is_newest'; public $isRecommendField = 'is_recommend'; public $recommendImageField = 'recommend_image'; public $createdField = 'created_at'; public $updatedField = 'updated_at'; function __construct(CoreDb $dbo){ $this->_dbo = $dbo; $this->init(); } protected function init(){ $this->tableName = $this->_dbo->getDbUtils()->getTableName($this->tableName); } function find($cond, $fields='*'){ $sqlCond = CoreDbSqlHelper::parseConditions($this->_dbo,$cond);