日期:2014-05-16  浏览次数:20374 次

发布一个 分页条js实现... 很好用啊
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">&lt;&lt;&nbsp;<a class="paging-per" href="' + gurl(curPage-1) + '">上一页</a>&nbsp;</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">&nbsp;<a class="paging-per" href="' + gurl(1) + '">1</a>&nbsp;</span>';


	}


	


	if(start > 2){pageStr += '<span class="grey-12">&nbsp;...&nbsp;</span>';}


	


	for(var i=start; i<end; i++){


		if(i>totalPage) break;


		if(i == curPage){


			pageStr += '<span class="blue-12-bold">&nbsp;<a class="paging-per paging-current" href="' + gurl(i) + '">' + i + '</a>&nbsp;</span>';


		}else{


			pageStr += '<span class="grey-12">&nbsp;<a class="paging-per" href="' + gurl(i) + '">' + i + '</a>&nbsp;</span>';	


		}


	}


	


	if(end < totalPage){


		pageStr += '<span class="grey-12">&nbsp;...&nbsp;</span>';


		pageStr += '<span class="grey-12">&nbsp;<a class="paging-per" href="' + gurl(totalPage) + '">' + totalPage + '</a>&nbsp;</span>';


	}


	


	if(curPage < totalPage){


		pageStr += '<span class="grey-12">&nbsp;<a class="paging-per" href="' + gurl(curPage+1) + '">下一页</a>&nbsp;&gt;&gt;</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>
?

?

?

1 楼 vb2005xu 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);