Asp.Net之JS生成分页条的方法
Default.aspx.cs中的代码
protected int pageIndex = 1; protected int pageSize = 10; protected int pageCount = 100; protected string name = string.Empty; protected void Page_Load(object sender, EventArgs e) { int.TryParse(Request.QueryString["pageIndex"],out pageIndex); name=Request.QueryString["name"]; }
Default.aspx.cs中的代码
Body中的内容
名称:<input type="text" id="txtName" value="<%=name %>" /> <div id="PageBar">
JS中的内容
<script src="jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> var pagecount=<%=pageCount %>; var pageindex=<%=pageIndex %>; var pageSize=<%=pageSize %>; $(function(){ createPageBar(pageindex,pagecount); }) //生成分页条 function createPageBar(pageindex,pageCount){ //拿到存放分页条的div并清空 var pageBarObj=$('#PageBar'); pageBarObj.html(''); //判断给定页码 if(pageindex<1){ pageindex=1; } if(pageindex>pageCount){ pageindex=pagecount; } //首页与上一页 $('<a href="javaScript:void(0)">首页</a> ').appendTo(pageBarObj).click(function(){ goPage(1); }); if(pageindex>1){ $('<a href="javaScript:void(0)">上一页</a> ').appendTo(pageBarObj).click(function(){ goPage(pageindex-1); }); } //数字分页 var start=pageindex-4; if(start<1){ start=1; } var end=start+9; if(end>pagecount){ end=pagecount; } for(var i=start;i<=end;i++){ $(' <a href="javascript:void(0)">['+i+']</a> ').appendTo(pageBarObj).click(function(){ goPage(i); }); } //下一页与尾页 if(pageindex<pagecount){ $('<a href="javaScript:void(0)">下一页</a> ').appendTo(pageBarObj).click(function(){ goPage(pageindex+1); }); } $('<a href="javaScript:void(0)">尾页</a>').appendTo(pageBarObj).click(function(){ goPage(pagecount); }); } //去跳转 function goPage(pageindex){ var name=$('#txtName').val(); window.location="/Default.aspx?pageindex="+pageindex+"&name="+name; } </script>
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10