163 AJAX Tab

时间:2021-05-28

复制代码 代码如下:
//163AJAXTab
//update2006.10.18
//增加鼠标延迟感应特性。
//update2006.10.8
//A标签href属性将保持原有HTML功能。增加urn属性为AJAXLoad路径。
//update2006.10.11
//修正IE5.0undefined未定义错误,增加脚本错误屏蔽
varBrowser=newObject();
Browser.isMozilla=(typeofdocument.implementation!='undefined')&&(typeofdocument.implementation.createDocument!='undefined')&&(typeofHTMLDocument!='undefined');
Browser.isIE=window.ActiveXObject?true:false;
Browser.isFirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
if(Browser.isFirefox){//entendEventModforFireFox
extendEventObject();
}
functionextendEventObject(){
Event.prototype.__defineGetter__("srcElement",function(){
varnode=this.target;
while(node.nodeType!=1)node=node.parentNode;
returnnode;
});

Event.prototype.__defineGetter__("fromElement",function(){
varnode;
if(this.type=="mouseover")
node=this.relatedTarget;
elseif(this.type=="mouseout")
node=this.target;
if(!node)return;
while(node.nodeType!=1)node=node.parentNode;
returnnode;
});

Event.prototype.__defineGetter__("toElement",function(){
varnode;
if(this.type=="mouseout")
node=this.relatedTarget;
elseif(this.type=="mouseover")
node=this.target;
if(!node)return;
while(node.nodeType!=1)node=node.parentNode;
returnnode;
});
}
functionIsChild(cNode,pNode){
while(cNode!=null){
cNode=cNode.parentNode;
if(cNode==pNode)returntrue;
}
returnfalse;
}

varajccache=newObject();
varwaitInterval;
vartempref;
varMouseDelayTime=150;//鼠标感应延迟300毫秒
functiongetTBprefixName(str,sta){
if(str.indexOf("active")!=-1||str.indexOf("normal")!=-1)str=str.substr(6);
elseif(str.indexOf("over")!=-1)str=str.substr(4);
elsestr="";
returnsta+str;
}
functionstartajaxtabs(){
for(vari=0;i<arguments.length;i++)
{
varulobj=document.getElementById(arguments[i]);
ulist=ulobj.getElementsByTagName("li");
for(varj=0;j<ulist.length;j++)
{
varthelist=ulist[j];
if(thelist.parentNode.parentNode!=ulobj)continue;//只有第一层li有效fixed2006.9.29
varulistlink=thelist.getElementsByTagName("a")[0];
varulistlinkurl=ulistlink.getAttribute("urn");
varulistlinktarget=ulistlink.getAttribute("rel");
thelist.setActive=function(bactive){
if(bactive){
this.status="active";
this.className=getTBprefixName(this.className,"active");
}else{
this.status="normal";
this.className=getTBprefixName(this.className,"normal");
}
}
thelist.LoadTab=function(){
this.setActive(true);
this.parentNode.parentNode.activetab.setActive(false);
this.parentNode.parentNode.activetab=this;
varulistlink=this.getElementsByTagName("a")[0];
loadAJAXTab(ulistlink.getAttribute("urn"),ulistlink.getAttribute("rel"));
}
thelist.onmouseover=function(aEvent){
varmyEvent=window.event?window.event:aEvent;
varfm=myEvent.fromElement;
if(IsChild(fm,this)||fm==this)return;//过滤子元素event
if(this.status=="active")return;
tempref=this;
clearTimeout(waitInterval);
waitInterval=window.setTimeout("tempref.LoadTab();",MouseDelayTime);
}

thelist.onmouseout=function(aEvent){
varmyEvent=window.event?window.event:aEvent;
varem=myEvent.toElement;
if(IsChild(em,this)||em==this)return;//过滤子元素event
if(this.status=="active")return;
clearTimeout(waitInterval);
}

if(ulistlinkurl.indexOf("#default")!=-1){
thelist.setActive(true);
ulobj.activetab=thelist;
ajccache[ulistlinkurl]=getElement(ulistlinktarget).innerHTML;
}else{
thelist.setActive(false);
}

}
if(ulobj.activetab==null)ulobj.activetab=ulist[0];
}
}

functiongetXmlhttp()
{
varhttp_request;

if(window.XMLHttpRequest){
http_request=newXMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}
elseif(window.ActiveXObject){
try{
http_request=newActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request=newActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request){
window.alert("can'tcreateXMLHttpRequestobject.");
returnnull;
}
returnhttp_request;
}

functionloadAJAXTab(url,contentid){
varocontent=getElement(contentid);
if(ajccache[url]==null){
varxhttp=getXmlhttp();
xhttp.onreadystatechange=function(){
if(xhttp.readyState==4&&(xhttp.status==200||window.location.href.indexOf("http")==-1))
{
ocontent.innerHTML=xhttp.responseText;
ajccache[url]=ocontent.innerHTML;
}
}
xhttp.open("GET",url,true);
xhttp.send(null);
}else{
ocontent.innerHTML=ajccache[url];
}
}
window.onerror=function(){returntrue}

具体使用方法,看用的

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

相关文章