jquery实现pager控件示例
jQuery 实现 示例 控件
2023-06-13 09:15:24 时间
js:
$.fn.extend({JPager:function(cfg,pageIndex,pageSize){
if(cfg&&pageIndex>0&&pageSize>0){
vartoken="#"+this.attr("id");
this.empty();
varpageFirst=function(){
$(token).JPager(cfg,1,pageSize);
};
varpagePre=function(){
$(token).JPager(cfg,pageIndex-1,pageSize);
};
varpageLast=function(){
$(token).JPager(cfg,parseInt($("#_tot").val()),pageSize);
};
varpageNext=function(){
$(token).JPager(cfg,pageIndex+1,pageSize);
};
varpageNumber=function(){
$(token).JPager(cfg,parseInt($(this).text()),pageSize);
};
varpageGo=function(){
varindex=parseInt($("#_pos").val());
vartotal=parseInt($("#_tot").val());
if(index){
if(index>total){
$(token).JPager(cfg,total,pageSize);
}
elseif(index<1){
$(token).JPager(cfg,1,pageSize);
}
else{
$(token).JPager(cfg,index,pageSize);
}
}
};
varcheckGoNumber=function(){
if(!Number(this.value)){
this.value="";
}
else{
this.value=Number(this.value);
}
};
varinitCustomer=function(recordCount){
if(cfg.customer){
if(cfg.customer.template){
vart=cfg.customer.template;
t=t.replace(/\%total\%/gi,Math.ceil(recordCount/pageSize)).replace(/\%current\%/gi,pageIndex).replace(/\%recordCount\%/gi,recordCount).replace(/\%pageSize\%/gi,pageSize);
if(cfg.customer.position=="right"){
$("#_right").after(t);
}
else{
$("#_left").before(t);
}
}
}
};
varchangeState=function(total){
if(pageIndex==1){
$("#_first").attr("class","unable");
$("#_pre").attr("class","unable");
}
else{
$("#_first").bind("click",pageFirst).attr("class","number");
$("#_pre").bind("click",pagePre).attr("class","number");
}
if(pageIndex==total){
$("#_last").attr("class","unable");
$("#_next").attr("class","unable");
}
else{
$("#_last").bind("click",pageLast).attr("class","number");
$("#_next").bind("click",pageNext).attr("class","number");
}
};
varinitNumber=function(total,count,current){
if(total>0&&count>0){
if(current<1){
current=1;
}
if(current>total){
current=total;
}
varendIndex=total;
varstartIndex=1;
vartemp=current+Math.floor(count/2);
if(temp<total){
if(temp<count){
endIndex=count;
}
else{
startIndex=temp-count+1;
endIndex=temp;
}
}
else{
if(total>count){
startIndex=total-count+1;
}
}
$("#_number").empty();
for(vari=startIndex;i<=endIndex;i++){
varhtml=$("<span></span>").text(i).bind("click",pageNumber);
if(i==current){
$("#_number").append(html.attr("class","selected"));
}
else{
$("#_number").append(html.attr("class","number"));
}
}
}
};
varinitPager=function(data){
if($.isArray(data.SearchResult)&&data.RecordCount>0){
$(token).append("<spanid="_left"><spanid="_first"class="spcial">首页</span> <spanid="_pre"class="spcial">上一页</span></span> <spanid="_number"></span><spanid="_go"><inputid="_pos"type="text"/><inputid="_to"type="button"value="GO"/></span> <spanid="_right"><spanid="_next"class="spcial">下一页</span> <spanid="_last"class="spcial">末页</span></span><inputid="_tot"type="hidden"/>");
vartotal=Math.ceil(data.RecordCount/pageSize);
$("#_tot").val(total);
$("#_pos").bind("blur",checkGoNumber);
$("#_to").bind("click",pageGo);
changeState(total);
if(cfg.showNumber&&cfg.count>0){
initNumber(total,cfg.count,pageIndex);
}
initCustomer(data.RecordCount);
}
};
if(cfg.action){
if(cfg.action.url&&cfg.action.data){
vard=cfg.action.data.substr(0,cfg.action.data.lastIndexOf("}"))+","pageIndex":"+pageIndex+","pageSize":"+pageSize+"}";
if(cfg.action.callback&&$.isFunction(cfg.action.callback)){
$.ajax({
type:"post",
url:cfg.action.url,
dataType:"json",
contentType:"text/json",
data:d,
success:function(data){
initPager(data.d);
cfg.action.callback(data.d);
}
});
}
else{
$.ajax({
type:"post",
url:cfg.action.url,
dataType:"json",
contentType:"text/json",
data:d,
success:function(data){
initPager(data.d);
}
});
}
}
}
}
}
});
css:
#_pos{
width:40px;
}
.unable
{
color:#BCC0BB;
}
.number
{
margin:2px;
color:#0000FF;
text-decoration:underline;
}
.selected
{
margin:2px;
color:#FF0000;
font-weight:bold;
}
html:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>分页控件示例</title>
<linkhref="CSS/JPager.css"rel="stylesheet"type="text/css"/>
<scriptsrc="JS/jquery.min.js"type="text/javascript"></script>
<scriptsrc="JExtension/JPager.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$("#pager").JPager({customer:{template:"%cuRRent%"},count:10,action:{url:"Service/JService.svc/GetPersons",data:"{"name":"zhoulq"}"},showNumber:true},1,5);
});
</script>
</head>
<body>
<table>
</table>
<divid="pager"></div>
</body>
</html>
wcf:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Runtime.Serialization;
usingSystem.ServiceModel;
usingSystem.ServiceModel.Activation;
usingSystem.ServiceModel.Web;
namespaceJPlugin
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
publicclassJService
{
[OperationContract]
[WebInvoke]
publicPageObject<Person>GetPersons(stringname,intpageIndex,intpaseSize)
{
returnnewPageObject<Person>(){RecordCount=23,SearchResult=newList<Person>(){newPerson(){Name="zhpulq",Age=28},newPerson(){Name="zhouxy",Age=24}}};
}
}
publicclassPageObject<T>
{
publicintRecordCount{get;set;}
publicList<T>SearchResult{get;set;}
}
}
相关文章
- Javascript链式调用实现代码(参考jquery)
- 基于jquery的实现简单的表格中增加或删除下一行
- jquery实现点击TreeView文本父节点展开/折叠子节点
- S2SH整合JQuery+Ajax实现登录验证功能实现代码
- jQuery实现用户注册的表单验证示例
- jquery实现metro效果示例代码
- jquery实现按Enter键触发事件示例
- jquery实现滑动图片自己测试的例子
- jquery实现图片灯箱明暗的遮罩效果
- jquery+json实现数据列表分页示例代码
- jquery.autocomplete修改实现键盘上下键自动填充示例
- jquery实现背景墙聚光灯效果示例分享
- jquery实现select选中行、列合计示例
- jquery实现带二级菜单的导航示例
- 用jquery.sortElements实现table排序
- jquery实现图片按比例缩放示例
- Jquery仿IGoogle实现可拖动窗口示例代码
- jquery实现类似淘宝星星评分功能实例