js+ajax+jquery无刷新分页 有点凌乱 大家将就看吧?

我分享我快乐~

先上代码

<div  >
<span></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" >第一页</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" >上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" >下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" >末页</a>
</div>

  这是使用://这是个好习惯 你写的代码放到这"块"里边 可以解决 全局变量变局部变量的问题

$(function(){
//下边的所有代码在这里边
});

  

     var onepagecout=2;//每页显示多少个
var number;//当前菜单的index
var pagecount;//总页数
var temp;
var pageindex=1;
    pc();

总页数:

//总页数
function pc()
{
//没有数据则加载
if(typeof(count)=="undefined" || typeof(pagecount)=="undefined")
{
var count=KnowledgebaseIndex.GetCount(zhuanhuan(number)).value;
pagecount=Math.ceil(count/onepagecout);
}
}

  

 //设置首页的链接
$("#fenye a:eq(0)").click(function(){
pageindex=1;
show();//show data
});
//设置最后一页的链接
$("#fenye a:eq(3)").click(function(){
pageindex=pagecount;
show();//show data
});
//上一页
$("#fenye a:eq(1)").click(function(){
if(pageindex>1 && pagecount>1)
{
pageindex=pageindex-1;
show();//show data
}
});
//下一页
$("#fenye a:eq(2)").click(function(){
if(pageindex<pagecount && pagecount>1)
{
pageindex=pageindex+1;
show();//show data
}

 

  function show(){
fake_sidebar.innerHTML="\<div fake_sidebar_row1\">\
<div Mfake_sidebar_row1_column1\">&nbsp;&nbsp;标题</div>\
<div Mfake_sidebar_row1_column2\">&nbsp;&nbsp;by</div>\
<div Mfake_sidebar_row1_column3\">&nbsp;&nbsp;时间</div>\
<div>下载</div>\
</div>"+KnowledgebaseIndex.GetKnowledgebaseInfoData(where,onepagecout,pageindex).value;//where是条件
$("#fenye span").html(""+pageindex+"/"+pagecount);//设置当前页数和总页数
}

  俺的sql

  public static string GetKnowledgebaseInfoData(string Contenttype, int onepagecout, int pageindex)
{
string rstring = "";
string SQLString = "select top " + onepagecout + " ZSKTitle,DateTimeInfo,FileName,FileUrl,ID,empid from Knowledgebase where id>(select isnull(max(id),0) from(select top ((" + pageindex + "-1)*" + onepagecout + ") id from Knowledgebase where FileType='" + Contenttype + "' order by id) as T) and FileType='" + Contenttype + "' order by id";
//string SQLString = "select ZSKTitle,DateTimeInfo,FileName,FileUrl,ID,empid from Knowledgebase where FileType='" + Contenttype + "' order by ID desc";
string result = TotalMethod.GetSQLstringHTMLstring(SQLString, 6);
if (result != "")
{
string[] sub = result.Split('$');
rstring += "<div class='fake_sidebar_rowother'>";
foreach (string val in sub)
{
string[] num = val.Split('*');
string content = num[0].ToString();
if (content.Length > 25)
{
content = content.Substring(0, 25) + "...";
}
rstring += "<div class='Mfake_sidebar_rowother_column1'>&nbsp;&nbsp;<a href='#' title='" + num[0].ToString() + "' onclick='$ExpandH(" + num[4].ToString() + ")'>" + content + "</a></div>";//标题
rstring += "<div class='Mfake_sidebar_rowother_column2'>|&nbsp;&nbsp;" + num[5].ToString() + "</div>";//时间
rstring += "<div class='Mfake_sidebar_rowother_column3'>|&nbsp;&nbsp;" + num[1].ToString() + "</div>";//时间
//如果下载路径不为空就显示下载
if (!num[3].Equals(""))
{
rstring += "<div ><a href='../wxDown.aspx?down=" + num[3].ToString() + "'>下载</a></div>";
}
else
{
rstring += "<div >下载</div>";
}
}
rstring += "</div>";
}
else
{
rstring = "<div class=\"fake_sidebar_rowother\">暂无任何数据!</div>";
}
return rstring;
}

  

分页sql:

select top 页大小 *
from table1
where id>
(select max (id) from
(select top ((页码-1)*页大小) id from table1 order by id) as T
)
order by id

  

推荐大家使用存储过程里边!!!!!!!!!!!!!

显示:

1/2 第一页上一页下一页末页

有些凌乱......