手机
当前位置:查字典教程网 >编程开发 >AJAX相关 >163 AJAX Tab
163 AJAX Tab
摘要:复制代码代码如下://163AJAXTab//update2006.10.18//增加鼠标延迟感应特性。//update2006.10.8/...

复制代码 代码如下:

//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}

具体使用方法,看www.163.com用的

【163 AJAX Tab】相关文章:

基于h5的history改善ajax列表请求体验

AjaxUI:鼠标拖拽

浅谈Ajax技术实现页面无刷新

AJAXRequest v0.2

AJax 学习笔记一(XMLHTTPRequest对象)

Ajax技术(WEB无刷新提交数据)

php AJAX POST的使用实例代码

Ajax in action 英文版配书源码 下载

Ajax中浏览器和服务器交互详解

基于AJAX的分页类实现代码

精品推荐
分类导航