浏览 6449 次
锁定老帖子 主题:发布一个 分页条js实现... 很好用啊
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-05-20
最后修改:2011-05-21
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>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-05-22
通用模型
<?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); if ($sqlCond) $sqlCond = "WHERE {$sqlCond}"; $qfields = CoreDbSqlHelper::qfields($fields,$this->tableName); $sql = "SELECT {$qfields} FROM {$this->tableName} {$sqlCond}" . CoreDbSqlHelper::getLimitSql(1); return $this->_dbo->getRow($sql); } function findAll($cond, $sort=null, $limit=null,& $counter=null, $fields='*'){ $sqlCond = CoreDbSqlHelper::parseConditions($this->_dbo,$cond); if ($sqlCond) $sqlCond = "WHERE {$sqlCond}"; if ($sort) $sort = "ORDER BY {$sort}"; $qfields = CoreDbSqlHelper::qfields($fields,$this->tableName); $counter = $counter ? 'SQL_CALC_FOUND_ROWS' : '' ; $sql = "SELECT {$counter} {$qfields} FROM {$this->tableName} {$sqlCond} {$sort}". CoreDbSqlHelper::getLimitSql($limit); $rows = $this->_dbo->getAll($sql); if ($counter) $counter = $this->_dbo->getOne('SELECT FOUND_ROWS()') ; return $rows; } function delete($cond){ $sqlCond = CoreDbSqlHelper::parseConditions($this->_dbo,$cond); if ($sqlCond) $sqlCond = "WHERE {$sqlCond}"; $sql = "DELETE FROM {$this->tableName} {$sqlCond}"; if ($this->_dbo->execute($sql)) return $this->_dbo->lastQueryAffectedRows(); return false; } function findByPkv($id, $fields='*') { return $this->find(array($this->primaryKey=>$id),$fields); } /** * 添加并返回插入的主键编号,必须提供questionField * * @var array $faq * * @return int */ function insert(array $faq){ if (!isset($faq[$this->questionField]) || empty($faq[$this->questionField])) return false; $faq[$this->createdField] = CURRENT_TIMESTAMP; $sql = CoreDbSqlHelper::getInsertSQL($faq,$this->tableName); if ($sql){ if ($this->_dbo->execute($sql,$faq,true)) return $this->_dbo->lastInsertId(); } return false; } function update(array $faq){ // 未指定主键 if (!isset($faq[$this->primaryKey])) return false; $faq[$this->updatedField] = CURRENT_TIMESTAMP; $sql = CoreDbSqlHelper::getUpdateSQL($this->_dbo,$faq,$this->primaryKey,$this->tableName); if ($sql){ if ($this->_dbo->execute($sql,$faq)) return $this->_dbo->lastQueryAffectedRows(); } return false; } } |
|
返回顶楼 | |
发表时间:2011-05-24
JS分页,对搜索引擎不友好,分页将不能被爬虫检索。
|
|
返回顶楼 | |
发表时间:2011-05-24
呵呵 ... 感觉没有什么大的关系吧
|
|
返回顶楼 | |
发表时间:2011-05-27
下载的东西是木马!
|
|
返回顶楼 | |
发表时间:2011-05-27
871656094 写道 下载的东西是木马!
木马?不可能吧 .... 估计是你自己的毛病... 你 会不会啊 |
|
返回顶楼 | |
发表时间:2011-05-27
4k 的 正则表达式调试工具 你说是木马 严重质疑 你rp
|
|
返回顶楼 | |
发表时间:2011-05-27
matyhtf 写道 JS分页,对搜索引擎不友好,分页将不能被爬虫检索。
确是如此 |
|
返回顶楼 | |