科讯商业版中用到的ajax空间与分页函数

时间:2021-05-18

科讯sql商业版中用到的ajax空间与分页函数,他们的js代码学习是非常不错的
//ajax控件
functionPageAjax(){
varxhrObj=null;
if(window.XMLHttpRequest)
{
xhrObj=newXMLHttpRequest();
}
elseif(window.ActiveXObject)
{
try{
xhrObj=newActiveXObject("Microsoft.XMLHTTP");
}
catch(e1)
{
try{
xhrObj=newActiveXObject("MSXML2.XMLHTTP");
}
catch(e2){
try{
xhrObj=newActiveXObject("MSXML3.XMLHTTP");
}
catch(e3){
alert("创建Ajax失败:"+e3)
}
}
}
}
else
{
alert("未能识别的浏览器");
}
returnxhrObj;
}

functionPage(curPage,labelid,classid,installdir,url,refreshtype,specialid)
{
this.labelid=labelid;
this.classid=classid;
this.url=url;
if(labelid.substring(0,5)=="{SQL_")
{
varslabelid=labelid.split('(')[0];
slabelid=slabelid.replace("{","");
this.c_obj="c_"+slabelid;
this.p_obj="p_"+slabelid;
}
else
{
this.c_obj="c_"+labelid;
this.p_obj="p_"+labelid;
}
this.installdir=installdir;
this.refreshtype=refreshtype;
this.specialid=specialid;
this.page=curPage;
loadData(1);
}
functionloadData(p)
{this.page=p;
varxhr=newPageAjax();
xhr.open("get",installdir+url+"?labelid="+escape(labelid)+"&classid="+classid+"&refreshtype="+refreshtype+"&specialid="+specialid+"&curpage="+p,true);
xhr.onreadystatechange=function(){
if(xhr.readyState==1)
{
if(p==1)
eval('document.all.'+c_obj).innerHTML="<divalign='center'><imgsrc='"+installdir+"images/loading.gif'>正在连接服务器...</div>";
}
elseif(xhr.readyState==2||xhr.readyState==3)
{
if(p==1)
eval('document.all.'+c_obj).innerHTML="<divalign='center'><imgsrc='"+installdir+"images/loading.gif'>正在读取数据...</div>";
}
elseif(xhr.readyState==4)
{
if(xhr.status==200)
{
varpagearr=xhr.responseText.split("{ks:page}")
varpageparamarr=pagearr[1].split("|");
count=pageparamarr[0];
perpagenum=pageparamarr[1];
pagecount=pageparamarr[2];
itemunit=pageparamarr[3];
itemname=pageparamarr[4];
pagestyle=pageparamarr[5];
getObject(c_obj).innerHTML=pagearr[0];
pagelist();
}
}
}
xhr.send(null);
}
functiongetObject(id)
{
if(document.getElementById)
{
returndocument.getElementById(id);
}
elseif(document.all)
{
returndocument.all[id];
}
elseif(document.layers)
{
returndocument.layers[id];
}
}

functionpagelist()
{
varn=1;
varstatushtml=null;
switch(parseInt(this.pagestyle))
{
case1:
statushtml="共"+this.count+this.itemunit+"<ahref=\"javascript:homePage(1);\"title=\"首页\">首页</a><ahref=\"javascript:previousPage()\"title=\"上一页\">上一页</a>&nbsp;<ahref=\"javascript:nextPage()\"title=\"下一页\">下一页</a><ahref=\"javascript:lastPage();\"title=\"最后一页\">尾页</a>页次:<fontcolor=red>"+this.page+"</font>/"+this.pagecount+"页"+this.perpagenum+this.itemunit+this.itemname+"/页";
break;
case2:
statushtml="<ahref='#'>"+this.pagecount+"页/"+this.count+this.itemunit+"</a><ahref=\"javascript:homePage(1);\"title=\"首页\"><fontface=webdings>9</font></a><ahref=\"javascript:previousPage()\"title=\"上一页\"><fontface=webdings>7</font></a>&nbsp;";
varstartpage=1;
if(this.page==10)
startpage=2;
elseif(this.page>10)
startpage=eval((parseInt(this.page/10)-1)*10+parseInt((this.page)%10)+2);
for(vari=startpage;i<=this.pagecount;i++){
if(i==this.page)
statushtml+="<ahref=\"#\"><fontcolor=\"#ff0000\">"+i+"</font></a>&nbsp;"
else
statushtml+="<ahref=\"javascript:turn("+i+")\">"+i+"</a>&nbsp;"
n=n+1;
if(n>10)break;
}
statushtml+="<ahref=\"javascript:nextPage()\"title=\"下一页\"><fontface=webdings>8</font></a><ahref=\"javascript:lastPage();\"title=\"最后一页\"><fontface=webdings>:</font></a>";
statushtml="<spanclass='kspage'>"+statushtml+"</span>";
break;
case4:
statushtml="共"+this.pagecount+"页/"+this.count+this.itemunit+this.itemname+"<ahref=\"javascript:homePage(1);\"title=\"首页\"><fontface=webdings>9</font></a><ahref=\"javascript:previousPage()\"title=\"上一页\"><fontface=webdings>7</font></a>&nbsp;";
for(vari=this.page;i<=this.pagecount;i++){
if(i==this.page)
statushtml+="<b><fontcolor=\"#ff0000\">"+i+"</font></b>&nbsp;"
else
statushtml+="<ahref=\"javascript:turn("+i+")\">["+i+"]</a>&nbsp;"
n=n+1;
if(n>10)break;
}
statushtml+="<ahref=\"javascript:nextPage()\"title=\"下一页\"><fontface=webdings>8</font></a><ahref=\"javascript:lastPage();\"title=\"最后一页\"><fontface=webdings>:</font></a>";
break;
case3:
statushtml="第<fontcolor=#ff000>"+this.page+"</font>页共"+this.pagecount+"页<ahref=\"javascript:homePage(1);\"title=\"首页\"><<</a><ahref=\"javascript:previousPage()\"title=\"上一页\"><</a>&nbsp;<ahref=\"javascript:nextPage()\"title=\"下一页\">></a><ahref=\"javascript:lastPage();\"title=\"最后一页\">>></a>"+this.perpagenum+this.itemunit+this.itemname+"/页";
break;
}
statushtml+="&nbsp;第<selectname=\"goto\"onchange=\"turn(parseInt(this.value));\">";
for(vari=1;i<=this.pagecount;i++){
if(i==this.page)
statushtml+="<optionvalue='"+i+"'selected>"+i+"</option>";
else
statushtml+="<optionvalue='"+i+"'>"+i+"</option>";
}
statushtml+="</select>页";
getObject(this.p_obj).innerHTML=statushtml;
}
functionhomePage()
{
if(this.page==1)
alert("已经是首页了!")
else
loadData(1);
}
functionlastPage()
{
if(this.page==this.pagecount)
alert("已经是最后一页了!")
else
loadData(this.pagecount);
}
functionpreviousPage()
{
if(this.page>1)
loadData(this.page-1);
else
alert("已经是第一页了");
}

functionnextPage()
{
if(this.page<this.pagecount)
loadData(this.page+1);
else
alert("已经到最后一页了");
}
functionturn(i)
{
loadData(i);
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章