溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Ajax怎么實(shí)現(xiàn)標(biāo)簽導(dǎo)航效果

發(fā)布時(shí)間:2021-09-02 13:53:44 來(lái)源:億速云 閱讀:113 作者:chen 欄目:web開發(fā)

本篇內(nèi)容主要講解“Ajax怎么實(shí)現(xiàn)標(biāo)簽導(dǎo)航效果”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Ajax怎么實(shí)現(xiàn)標(biāo)簽導(dǎo)航效果”吧!

代碼如下:


<!--
function getObject(objectId) {
     if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
       return document.getElementById(objectId);
     } 
     else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
       return document.all(objectId);
     } 
     else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
       return document.layers[objectId];
     } 
     else {
       return false;
    }


var responsecont;
var xmlHttp;
var requestType;
var newsstring;
var ajccache=new Object();//緩存已訪問(wèn)的數(shù)據(jù)頁(yè)面
var url;
var MouseDelayTime=150;//鼠標(biāo)感應(yīng)延遲
var waitInterval;

function CreateXMLHttpRequest(){
   // Initialize Mozilla XMLHttpRequest object
   if (window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
   } 
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject) {
       try{
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
       } 
       catch (e){
            try{
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){newsstring = "<div class='loading'>Loading rquest content fail, Please try it again latter...</div>";}
       }
   }
}

function getnews(tagid,x){
   url = "tab/"+tagid+'_'+x+'.html';
//   var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
   requestType = tagid;


if(ajccache[url]==null){
   CreateXMLHttpRequest();   

//   getObject(requestType+'_cnt').innerHTML = loadstatustext;
   xmlHttp.onreadystatechange = processRequestChange;
   xmlHttp.open("GET", url, true);
   xmlHttp.setRequestHeader("If-Modified-Since","0");
   xmlHttp.send(null);  
}
else
{  shownews(requestType,ajccache[url]);    }
}

function processRequestChange(){
   // only if xmlHttp shows "complete"
   if (xmlHttp.readyState == 4){
      // only http 200 to process
      if (window.location.href.indexOf("http")==-1 || xmlHttp.status == 200){
         newsstring = xmlHttp.responseText;
         //inject centent to tab-pane
            shownews(requestType,newsstring);
            ajccache[url]=newsstring;    //把已訪問(wèn)的數(shù)據(jù)緩存下來(lái)
      }
   }
}

function shownews(requestType,newsstring){
//<![CDATA[
    responsecont = getObject(requestType+'_cnt');
    responsecont.innerHTML = newsstring;
//]]>
}

function TabNews(tagid,x){
    for (var i=1;i<=7;i+=2) {
         if (i == x) {
            getObject(tagid+i).className="tabactive"+i;
            if(i!=1){
               getObject(tagid+(i-1)).style.display="none";               
               if(i!=7){
                  getObject(tagid+(i+1)).style.display="none";
               }                 
            }
            if(i==1){
               getObject(tagid+"2").style.display="none";
            } 
            try{            
               getnews(tagid,i);
            }
            catch(e){
               alert(e);
            }  
        }
        else
        {
            getObject(tagid+i).className="";            
            if(i!=7){
               getObject(tagid+(i+1)).style.display="block";
            }             
        }         
   }
}

var idn;

function aet(objid,tagid,etp){    //為L(zhǎng)I加上事件    objid:容器ID  tagid:組別   etp:觸發(fā)類型 0-onmouseover 1-onclick
    var iif=0;
    var lis=objid.getElementsByTagName('li');
    requestType=tagid;
    url = "tab/"+requestType+"_1.html";
    ajccache[url]=getObject(requestType+'_cnt').innerHTML;
    for(var iy=0;iy<lis.length;iy++){
        if(iif==0){
        iif=1;
        with(lis[iy]){
        if(etp==0){
        lis[iy].onmouseover=function(){
                    if(this.status=="active") return;
                    requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
                    idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
                    clearTimeout(waitInterval);
                    waitInterval=window.setTimeout("TabNews(requestType,idn);",MouseDelayTime);
            }
        lis[iy].onmouseout=function(){if(this.status=="active") return;clearTimeout(waitInterval);}
        } 
        if(etp==1){
        lis[iy].onmouseover=function(){}
        lis[iy].onclick=function(){
                    if(this.status=="active") return;
                    requestType=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
                    idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
                    var loadstatustext="<div class='loading'><img src='images/loading.gif' /> Loading request content, please wait...</div>";
                    getObject(requestType+'_cnt').innerHTML = loadstatustext;
                    TabNews(requestType,idn);
            }}}}
        else{iif=0;}
    }



function ata(objid){    //一個(gè)無(wú)關(guān)的函數(shù),為解決一個(gè)鏈接問(wèn)題
var as=objid.getElementsByTagName('a');
for(var i=0;i<as.length;i++){
as[i].pathname="/showfile.html";
}

}
//-->

到此,相信大家對(duì)“Ajax怎么實(shí)現(xiàn)標(biāo)簽導(dǎo)航效果”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI