您好,登錄后才能下訂單哦!
本篇內容主要講解“Ajax怎么實現標簽導航效果”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Ajax怎么實現標簽導航效果”吧!
代碼如下:
<!--
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();//緩存已訪問的數據頁面
var url;
var MouseDelayTime=150;//鼠標感應延遲
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; //把已訪問的數據緩存下來
}
}
}
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){ //為LI加上事件 objid:容器ID tagid:組別 etp:觸發類型 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){ //一個無關的函數,為解決一個鏈接問題
var as=objid.getElementsByTagName('a');
for(var i=0;i<as.length;i++){
as[i].pathname="/showfile.html";
}
}
//-->
到此,相信大家對“Ajax怎么實現標簽導航效果”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。