163 AJAX Tab

2016-02-19 13:03 3 1 收藏

清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐163 AJAX Tab,无聊中的都看过来。

【 tulaoshi.com - Web开发 】

代码如下:

// 163 AJAX Tab  
// update 2006.10.18 
// 增加鼠标延迟感应特性。 
// update 2006.10.8 
// A 标签 href 属性将保持原有HTML功能。增加urn属性为AJAX Load 路径。 
// update 2006.10.11 
// 修正IE5.0 undefined 未定义错误,增加脚本错误屏蔽 
var Browser = new Object(); 
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='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) { // entend Event Mod for FireFox 
    extendEventObject(); 

function extendEventObject() { 
    Event.prototype.__defineGetter__("srcElement", function () { 
        var node = this.target; 
        while (node.nodeType != 1) node = node.parentNode; 
        return node; 
    }); 

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

    Event.prototype.__defineGetter__("toElement", function () { 
        var node; 
        if (this.type == "mouseout") 
            node = this.relatedTarget; 
        else if (this.type == "mouseover") 
            node = this.target; 
        if (!node) return; 
        while (node.nodeType != 1) node = node.parentNode; 
        return node; 
    }); 

function IsChild(cNode,pNode){ 
    while(cNode!=null){ 
        cNode=cNode.parentNode; 
        if(cNode==pNode) return true;  
    } 
    return false; 


var ajccache=new Object(); 
var waitInterval; 
var tempref; 
var MouseDelayTime=150;//鼠标感应延迟300毫秒 
function getTBprefixName(str,sta){ 
    if(str.indexOf("active")!=-1 || str.indexOf("normal")!=-1) str=str.substr(6); 
        else if(str.indexOf("over")!=-1) str=str.substr(4); 
            else str=""; 
    return sta+str; 

function startajaxtabs(){ 
    for(var i=0;iarguments.length;i++) 
    { 
        var ulobj=document.getElementById(arguments[i]); 
            ulist=ulobj.getElementsByTagName("li");             
            for(var j=0;julist.length;j++) 
            { 
                var thelist=ulist[j]; 
                if(thelist.parentNode.parentNode!=ulobj) continue;//只有第一层li有效 fixed 2006.9.29 
                var ulistlink=thelist.getElementsByTagName("a")[0]; 
                var ulistlinkurl=ulistlink.getAttribute("urn"); 
                var ulistlinktarget=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;                     
                    var ulistlink=this.getElementsByTagName("a")[0]; 
                    loadAJAXTab(ulistlink.getAttribute("urn"),ulistlink.getAttribute("rel")); 
                } 
                thelist.onmouseover=function(aEvent){ 
                    var myEvent = window.event ? window.event : aEvent; 
                    var fm=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){ 
                    var myEvent = window.event ? window.event : aEvent; 
                    var em=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]; 
    } 


function getXmlhttp() 

    var http_request; 

    if(window.XMLHttpRequest) {  
        http_request = new XMLHttpRequest(); 
        if (http_request.overrideMimeType) { 
            http_request.overrideMimeType("text/xml"); 
        } 
    } 
    else if (window.ActiveXObject) {  
        try { 
            http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try { 
                http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e) {} 
        } 
    } 
    if (!http_request) {  
        window.alert("can't create XMLHttpRequest object."); 
        return null; 
    }     
    return http_request; 


function loadAJAXTab(url,contentid){ 
    var ocontent=getElement(contentid); 
    if(ajccache[url]==null) { 
        var xhttp=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(){return true}

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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

来源:https://www.tulaoshi.com/n/20160219/1602834.html

延伸阅读
标签: Web开发
AJAX介绍      AJAX 关键词:   JavaScript脚本和可扩展标记语言(XML)   WEB浏览器技术   开放式WEB标准   浏览器以及独立平台   更好更快的网络应用程序   XML以及HTTP请求      AJAX = 异步JavaScript和可扩展标记语言   A...
标签: 牛肉
咖喱浓香肉丸#宜家让家更有味#的做法步骤 1. 准备好所有的材料,忘记了拍椰浆和青红椒了。 2. 将宜家瑞士肉丸室温解冻,或放在微波炉解冻3分钟。将青红椒及洋葱切粒,姜切丝,蒜瓣用刀拍成碎沫。 ...
很多时候,我们都用Tab键来移动输入焦点,但是有些情况下,比如输入用户名后还需要输入密码,由于习惯性,你有可能在输入用户名后就按了一下回车,希望到密码框里继续输入,可是却按了确定键,报告密码错误,所以使用以下代码来让回车键代替TAB键下移一个控件: 在窗体上放两个控件,Edit1和Edit2,再加入下列代码拦截击键: Pr...
AJAX介绍 AJAX 关键词: javascript脚本和可扩展标记语言(XML)  WEB浏览器技术  开放式WEB标准  浏览器以及独立平台  更好更快的网络应用程序  XML以及HTTP请求  AJAX = 异步JavaScript和可扩展标记语言 AJAX是一种运用JavaScript和可扩展标记...
标签: 电脑入门
大家都知通,Tab是跳格键,比如写文章时开头要空两格就可用这个键。不过它还有别的作用,比如在表格中从前面的格跳到后面的格.在程序界面中从一个项目跳到另一个项目。编程人员用它来实现程序文本的格式化对齐等。此外,它还常与其他控制键联合使用。实现倒序或跨距离跳转等特殊跳转。 在打开的项目之间切换在Windows中.如果你打开了许多面口...

经验教程

584

收藏

48

精华推荐

Tab键的多种用途

Tab键的多种用途

爱梦157

AJAX教程(3):AJAX实例

AJAX教程(3):AJAX实例

鱼愿浅眠2

AJAX教程(1):AJAX简介

AJAX教程(1):AJAX简介

任丽虎

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部