欢迎来到福编程网,本站提供各种互联网专业知识!

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

发布时间:2007-09-02 作者: 来源:转载
科讯sql商业版中用到的ajax空间与分页函数,他们的js代码学习是非常不错的//ajax控件functionPageAjax(){varxhrObj=null;if(window.XMLHttpRequest){xhrObj=newXMLHttpRequest();}elseif(window.ActiveXObject){try{xhrObj=newActiveXObject("Microsoft.XMLHT
科讯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="正在连接服务器...

";
}
elseif(xhr.readyState==2||xhr.readyState==3)
{
if(p==1)
eval('document.all.'+c_obj).innerHTML="正在读取数据...
";
}
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+"首页上一页下一页尾页页次:"+this.page+"/"+this.pagecount+"页"+this.perpagenum+this.itemunit+this.itemname+"/页";
break;
case2:
statushtml=""+this.pagecount+"页/"+this.count+this.itemunit+"97";
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+=""+i+""
else
statushtml+=""+i+""
n=n+1;
if(n>10)break;
}
statushtml+="8:";
statushtml=""+statushtml+"";
break;
case4:
statushtml="共"+this.pagecount+"页/"+this.count+this.itemunit+this.itemname+"97";
for(vari=this.page;i<=this.pagecount;i++){
if(i==this.page)
statushtml+=""+i+""
else
statushtml+="["+i+"]"
n=n+1;
if(n>10)break;
}
statushtml+="8:";
break;
case3:
statushtml="第"+this.page+"页共"+this.pagecount+"页<<<>>>"+this.perpagenum+this.itemunit+this.itemname+"/页";
break;
}
statushtml+="第<selectname="goto"onchange="turn(parseInt(this.value));">";
for(vari=1;i<=this.pagecount;i++){
if(i==this.page)
statushtml+=""+i+"";
else
statushtml+=""+i+"";
}
statushtml+="页";
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.pageloadData(this.page+1);
else
alert("已经到最后一页了");
}
functionturn(i)
{
loadData(i);
}

相关推荐